From 8022f41fc08b2374f2b88c54755bcdf5130c79ac Mon Sep 17 00:00:00 2001 From: Julian Fleischer Date: Thu, 11 Oct 2018 14:29:00 +0200 Subject: [PATCH] move proposer* from esperanza/ to proposer/ (#156) --- src/Makefile.am | 14 +++++------ src/Makefile.test.include | 4 ++-- src/esperanza/walletextension.cpp | 6 ++--- src/esperanza/walletextension.h | 8 +++---- src/init.cpp | 10 ++++---- src/{esperanza => proposer}/proposer.cpp | 15 ++++++------ src/{esperanza => proposer}/proposer.h | 18 +++++++------- src/{esperanza => proposer}/proposer_init.cpp | 10 ++++---- src/{esperanza => proposer}/proposer_init.h | 6 ++--- .../rpcproposer.cpp => rpc/proposer.cpp} | 12 +++++----- .../rpcproposer.h => rpc/proposer.h} | 0 src/test/{ => proposer}/proposer_tests.cpp | 24 +++++++++---------- 12 files changed, 64 insertions(+), 63 deletions(-) rename src/{esperanza => proposer}/proposer.cpp (96%) rename src/{esperanza => proposer}/proposer.h (93%) rename src/{esperanza => proposer}/proposer_init.cpp (88%) rename src/{esperanza => proposer}/proposer_init.h (84%) rename src/{esperanza/rpcproposer.cpp => rpc/proposer.cpp} (88%) rename src/{esperanza/rpcproposer.h => rpc/proposer.h} (100%) rename src/test/{ => proposer}/proposer_tests.cpp (87%) diff --git a/src/Makefile.am b/src/Makefile.am index 400eb7c07a..0e61265a45 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -109,10 +109,7 @@ UNITE_CORE_H = \ esperanza/finalizationstate.h \ esperanza/init.h \ esperanza/kernel.h \ - esperanza/proposer.h \ - esperanza/proposer_init.h \ esperanza/params.h \ - esperanza/rpcproposer.h \ esperanza/settings.h \ esperanza/settings_init.h \ esperanza/stakevalidation.h \ @@ -153,6 +150,8 @@ UNITE_CORE_H = \ policy/policy.h \ policy/rbf.h \ pow.h \ + proposer/proposer.h \ + proposer/proposer_init.h \ proposer/transactionpicker.h \ protocol.h \ random.h \ @@ -162,6 +161,7 @@ UNITE_CORE_H = \ rpc/client.h \ rpc/esperanza.h \ rpc/mining.h \ + rpc/proposer.h \ rpc/protocol.h \ rpc/safemode.h \ rpc/server.h \ @@ -265,7 +265,6 @@ libunite_server_a_SOURCES = \ policy/policy.cpp \ policy/rbf.cpp \ pow.cpp \ - proposer/transactionpicker.cpp \ rest.cpp \ rpc/blockchain.cpp \ rpc/esperanza.cpp \ @@ -311,12 +310,13 @@ libunite_wallet_a_SOURCES = \ address/address.cpp \ esperanza/init.cpp \ esperanza/kernel.cpp \ - esperanza/proposer.cpp \ - esperanza/proposer_init.cpp \ - esperanza/rpcproposer.cpp \ esperanza/stakevalidation.cpp \ esperanza/walletextension.cpp \ key/mnemonic/mnemonic.cpp \ + proposer/proposer.cpp \ + proposer/proposer_init.cpp \ + proposer/transactionpicker.cpp \ + rpc/proposer.cpp \ unilib/uninorms.cpp \ unilib/utf8.cpp \ wallet/crypter.cpp \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 14169cbb13..d5b9a2a6ca 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -70,7 +70,6 @@ UNITE_TESTS =\ test/policyestimator_tests.cpp \ test/pow_tests.cpp \ test/prevector_tests.cpp \ - test/proposer/blockassembleradapter_tests.cpp \ test/raii_event_tests.cpp \ test/random_tests.cpp \ test/reverselock_tests.cpp \ @@ -111,7 +110,8 @@ UNITE_TESTS =\ if ENABLE_WALLET UNITE_TESTS += \ test/mnemonic_tests.cpp \ - test/proposer_tests.cpp \ + test/proposer/blockassembleradapter_tests.cpp \ + test/proposer/proposer_tests.cpp \ wallet/test/wallet_test_fixture.cpp \ wallet/test/wallet_test_fixture.h \ wallet/test/accounting_tests.cpp \ diff --git a/src/esperanza/walletextension.cpp b/src/esperanza/walletextension.cpp index f9d7e3883d..2fe048eb5a 100644 --- a/src/esperanza/walletextension.cpp +++ b/src/esperanza/walletextension.cpp @@ -5,12 +5,12 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include + #include #include #include -#include #include -#include #include #include #include @@ -792,7 +792,7 @@ void WalletExtension::BlockConnected( } } -const Proposer::State &WalletExtension::GetProposerState() const { +const proposer::Proposer::State &WalletExtension::GetProposerState() const { return m_proposerState; } diff --git a/src/esperanza/walletextension.h b/src/esperanza/walletextension.h index f3945fe071..bbb481d42d 100644 --- a/src/esperanza/walletextension.h +++ b/src/esperanza/walletextension.h @@ -6,12 +6,12 @@ #define UNITE_ESPERANZA_WALLETEXTENSION_H #include -#include #include #include #include #include #include +#include #include #include @@ -29,7 +29,7 @@ namespace esperanza { //! in bitcoin-core. The alterations done to wallet.h/wallet.cpp are kept to //! a minimum. All extended functionality should be put here. class WalletExtension { - friend class esperanza::Proposer; + friend class proposer::Proposer; private: //! a reference to the esperanza settings @@ -45,7 +45,7 @@ class WalletExtension { int m_deepestTxnDepth = 0; //! the state of proposing blocks from this wallet - Proposer::State m_proposerState; + proposer::Proposer::State m_proposerState; void VoteIfNeeded(const std::shared_ptr &pblock, const CBlockIndex *pindex); @@ -95,7 +95,7 @@ class WalletExtension { void BlockConnected(const std::shared_ptr &pblock, const CBlockIndex *pindex); - const Proposer::State &GetProposerState() const; + const proposer::Proposer::State &GetProposerState() const; ValidatorState validatorState; bool nIsValidatorEnabled = false; diff --git a/src/init.cpp b/src/init.cpp index 3246636d7e..ea8f8680da 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -52,8 +52,8 @@ #include #include #include -#include -#include +#include +#include #endif #include #include @@ -200,7 +200,7 @@ void Shutdown() StopRPC(); StopHTTPServer(); #ifdef ENABLE_WALLET - esperanza::StopProposer(); + proposer::StopProposer(); FlushWallets(); #endif MapPort(false); @@ -1854,10 +1854,10 @@ bool AppInitMain() // ********************************************************* Step 13: start proposing - if (!esperanza::InitProposer(*esperanzaSettings, vpwallets)) { + if (!proposer::InitProposer(*esperanzaSettings, vpwallets)) { return false; } - esperanza::StartProposer(); + proposer::StartProposer(); #endif LogPrintf("Started up.\n"); diff --git a/src/esperanza/proposer.cpp b/src/proposer/proposer.cpp similarity index 96% rename from src/esperanza/proposer.cpp rename to src/proposer/proposer.cpp index fb9ea1b177..bf8befff8f 100644 --- a/src/esperanza/proposer.cpp +++ b/src/proposer/proposer.cpp @@ -3,7 +3,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include
#include @@ -21,9 +21,10 @@ #include #include -namespace esperanza { +namespace proposer { -Proposer::Thread::Thread(const std::string &threadName, const Settings &config, +Proposer::Thread::Thread(const std::string &threadName, + const esperanza::Settings &config, const std::vector &wallets, CountingSemaphore &initSemaphore, CountingSemaphore &startSemaphore, @@ -59,7 +60,7 @@ void Proposer::Thread::SetStatus(const Proposer::Status status, } std::vector> Proposer::CreateProposerThreads( - const Settings &settings, const std::vector &wallets, + const esperanza::Settings &settings, const std::vector &wallets, CountingSemaphore &initSemaphore, CountingSemaphore &startSemaphore, CountingSemaphore &stopSemaphore) { // total number of threads can not exceed number of wallets @@ -98,7 +99,7 @@ std::vector> Proposer::CreateProposerThreads( return threads; } -Proposer::Proposer(const Settings &settings, +Proposer::Proposer(const esperanza::Settings &settings, const std::vector &wallets) : m_initSemaphore(0), m_startSemaphore(0), @@ -269,7 +270,7 @@ void Proposer::Run(Proposer::Thread &thread) { if (walletExt.SignBlock(blockTemplate.get(), bestHeight + 1, searchTime)) { const CBlock &block = blockTemplate->block; - if (!ProposeBlock(blockTemplate->block)) { + if (!esperanza::ProposeBlock(blockTemplate->block)) { LogPrint(BCLog::PROPOSING, "%s/%s: failed to propose block", thread.m_threadName, wallet->GetName()); continue; @@ -297,4 +298,4 @@ void Proposer::Run(Proposer::Thread &thread) { thread.m_stopSemaphore.release(); } -} // namespace esperanza +} // namespace proposer diff --git a/src/esperanza/proposer.h b/src/proposer/proposer.h similarity index 93% rename from src/esperanza/proposer.h rename to src/proposer/proposer.h index 994a0edbf1..5dea0f1329 100644 --- a/src/esperanza/proposer.h +++ b/src/proposer/proposer.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef UNITE_ESPERANZA_PROPOSER_H -#define UNITE_ESPERANZA_PROPOSER_H +#ifndef UNITE_PROPOSER_PROPOSER_H +#define UNITE_PROPOSER_PROPOSER_H #include #include @@ -20,7 +20,7 @@ class CWallet; -namespace esperanza { +namespace proposer { // a stub for testing – specializations of this class have access to the // Proposer's guts @@ -81,7 +81,7 @@ class Proposer { Proposer( //! [in] a name to derive thread names from (groupName-1, groupName-2, //! ...) - const Settings &, + const esperanza::Settings &, //! [in] a reference to all wallets to propose from const std::vector &wallets); @@ -105,7 +105,7 @@ class Proposer { const std::string m_threadName; //! unmodifiable reference to esperanza configuration - const Settings &m_settings; + const esperanza::Settings &m_settings; //! will be set to true to stop the thread std::atomic m_interrupted; @@ -130,7 +130,7 @@ class Proposer { //! [in] a name for this thread. const std::string &, //! [in] a reference to the global esperanza config - const Settings &, + const esperanza::Settings &, //! [in] the wallets which this thread is responsible for. const std::vector &, //! a semaphore for synchronizing initialization @@ -167,13 +167,13 @@ class Proposer { const std::vector> m_threads; static std::vector> CreateProposerThreads( - const Settings &settings, const std::vector &wallets, + const esperanza::Settings &settings, const std::vector &wallets, CountingSemaphore &initSemaphore, CountingSemaphore &startSemaphore, CountingSemaphore &stopSemaphore); static void Run(Thread &); }; -} // namespace esperanza +} // namespace proposer -#endif // UNITE_ESPERANZA_PROPOSER_H +#endif // UNITE_PROPOSER_PROPOSER_H diff --git a/src/esperanza/proposer_init.cpp b/src/proposer/proposer_init.cpp similarity index 88% rename from src/esperanza/proposer_init.cpp rename to src/proposer/proposer_init.cpp index f6d028ed7e..226200e19e 100644 --- a/src/esperanza/proposer_init.cpp +++ b/src/proposer/proposer_init.cpp @@ -2,19 +2,19 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include -#include +#include #include #include -namespace esperanza { +namespace proposer { static std::mutex initLock; static std::unique_ptr proposer = nullptr; -bool InitProposer(const Settings &settings, +bool InitProposer(const esperanza::Settings &settings, const std::vector &wallets) { std::unique_lock lock; if (proposer) { @@ -56,4 +56,4 @@ void WakeProposer(const CWallet *wallet) { } } -} // namespace esperanza +} // namespace proposer diff --git a/src/esperanza/proposer_init.h b/src/proposer/proposer_init.h similarity index 84% rename from src/esperanza/proposer_init.h rename to src/proposer/proposer_init.h index c77385166c..fcdddb846e 100644 --- a/src/esperanza/proposer_init.h +++ b/src/proposer/proposer_init.h @@ -11,9 +11,9 @@ class CWallet; -namespace esperanza { +namespace proposer { -bool InitProposer(const Settings &settings, +bool InitProposer(const esperanza::Settings &settings, const std::vector &wallets); void StartProposer(); @@ -22,6 +22,6 @@ void StopProposer(); void WakeProposer(const CWallet *wallet = nullptr); -} // namespace esperanza +} // namespace proposer #endif // UNIT_E_PROPOSER_INIT_H diff --git a/src/esperanza/rpcproposer.cpp b/src/rpc/proposer.cpp similarity index 88% rename from src/esperanza/rpcproposer.cpp rename to src/rpc/proposer.cpp index a2d4d9552e..e9ab821ee1 100644 --- a/src/esperanza/rpcproposer.cpp +++ b/src/rpc/proposer.cpp @@ -2,11 +2,11 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include -#include -#include +#include +#include #include #include #include @@ -50,7 +50,7 @@ UniValue proposerstatus(const JSONRPCRequest &request) { } UniValue proposerwake(const JSONRPCRequest &request) { - esperanza::WakeProposer(); + proposer::WakeProposer(); return proposerstatus(request); } @@ -58,8 +58,8 @@ UniValue proposerwake(const JSONRPCRequest &request) { static const CRPCCommand commands[] = { // category name actor (function) argNames // --------------------- ------------------------ ----------------------- ------------------------------------------ - { "esperanza", "proposerstatus", &proposerstatus, {}}, - { "esperanza", "proposerwake", &proposerwake, {}}, + { "proposer", "proposerstatus", &proposerstatus, {}}, + { "proposer", "proposerwake", &proposerwake, {}}, }; // clang-format on diff --git a/src/esperanza/rpcproposer.h b/src/rpc/proposer.h similarity index 100% rename from src/esperanza/rpcproposer.h rename to src/rpc/proposer.h diff --git a/src/test/proposer_tests.cpp b/src/test/proposer/proposer_tests.cpp similarity index 87% rename from src/test/proposer_tests.cpp rename to src/test/proposer/proposer_tests.cpp index 7c2dff588c..1b6a44431c 100644 --- a/src/test/proposer_tests.cpp +++ b/src/test/proposer/proposer_tests.cpp @@ -2,14 +2,14 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include #include #include -namespace esperanza { +namespace proposer { struct None {}; @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(start_stop) { CWallet wallet; wallets.emplace_back(&wallet); - esperanza::Proposer proposer(config, wallets); + proposer::Proposer proposer(config, wallets); proposer.Start(); proposer.Stop(); @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(stop_twice) { CWallet wallet; wallets.emplace_back(&wallet); - esperanza::Proposer proposer(config, wallets); + proposer::Proposer proposer(config, wallets); proposer.Start(); proposer.Stop(); @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(stop_without_start) { CWallet wallet; wallets.emplace_back(&wallet); - esperanza::Proposer proposer(config, wallets); + proposer::Proposer proposer(config, wallets); proposer.Stop(); } @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(stop_twice_without_start) { CWallet wallet; wallets.emplace_back(&wallet); - esperanza::Proposer proposer(config, wallets); + proposer::Proposer proposer(config, wallets); proposer.Stop(); proposer.Stop(); @@ -106,8 +106,8 @@ BOOST_AUTO_TEST_CASE(wallet_distribution) { wallets.emplace_back(&w10); wallets.emplace_back(&w11); - esperanza::Proposer proposer(config, wallets); - esperanza::ProposerSpy spy(proposer); + proposer::Proposer proposer(config, wallets); + proposer::ProposerSpy spy(proposer); BOOST_CHECK(spy.numThreads() == 3); BOOST_CHECK(spy.wallets(0).size() == 4); @@ -136,8 +136,8 @@ BOOST_AUTO_TEST_CASE(single_wallet_too_many_threads_specified) { CWallet wallet; wallets.emplace_back(&wallet); - esperanza::Proposer proposer(config, wallets); - esperanza::ProposerSpy spy(proposer); + proposer::Proposer proposer(config, wallets); + proposer::ProposerSpy spy(proposer); BOOST_CHECK(spy.numThreads() == 1); BOOST_CHECK(spy.wallets(0).size() == 1); @@ -153,8 +153,8 @@ BOOST_AUTO_TEST_CASE(single_wallet_too_few_threads_specified) { CWallet wallet; wallets.emplace_back(&wallet); - esperanza::Proposer proposer(config, wallets); - esperanza::ProposerSpy spy(proposer); + proposer::Proposer proposer(config, wallets); + proposer::ProposerSpy spy(proposer); BOOST_CHECK(spy.numThreads() == 1); BOOST_CHECK(spy.wallets(0).size() == 1);