From 22bbb591179d56d9078775c3337fd2e0c725cf88 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 27 Jun 2019 02:30:43 +0300 Subject: [PATCH] simplewallet: PoS mining in RPC mode made more kind to another wallet's instances (tx pool awareness, ZANO-385 --- src/simplewallet/simplewallet.cpp | 5 ----- src/wallet/wallet2.cpp | 12 ++++++++---- src/wallet/wallet_rpc_server.cpp | 21 +++++++++++++++++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 05703ced..4e3dbc18 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1597,11 +1597,6 @@ int main(int argc, char* argv[]) if (command_line::get_arg(vm, arg_generate_new_wallet).size()) return EXIT_FAILURE; - if (command_line::get_arg(vm, arg_do_pos_mining)) - { - message_writer(epee::log_space::console_color_magenta, true, "", 4) << "IMORTANT NOTICE! Instance started with \"do-pos-mining\" parameter, running copy of this wallet on other host at the same time may cause key image conflicts"; - } - if (!offline_mode) wal.refresh(); LOG_PRINT_GREEN("Loaded ok", LOG_LEVEL_0); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 44a78c5a..3f84adec 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2539,14 +2539,17 @@ bool wallet2::fill_mining_context(mining_context& ctx) bool wallet2::try_mint_pos() { mining_context ctx = AUTO_VAL_INIT(ctx); - WLT_LOG_L0("Starting PoS mint iteration"); + WLT_LOG_L1("Starting PoS mining iteration"); fill_mining_context(ctx); if (!ctx.rsp.is_pos_allowed) { - WLT_LOG_L0("POS MINING NOT ALLOWED YET"); + WLT_LOG_YELLOW("POS MINING NOT ALLOWED YET", LOG_LEVEL_0); return true; } - WLT_LOG_L0("POS_ENTRIES: " << ctx.sp.pos_entries.size()); + + uint64_t pos_entries_amount = 0; + for (auto& ent : ctx.sp.pos_entries) + pos_entries_amount += ent.amount; std::atomic stop(false); scan_pos(ctx, stop, [this](){ @@ -2564,7 +2567,8 @@ bool wallet2::try_mint_pos() { build_minted_block(ctx.sp, ctx.rsp); } - WLT_LOG_L0("PoS mint iteration finished(" << ctx.rsp.status << ")"); + + WLT_LOG_L0("PoS mining iteration finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); return true; } diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index fa29b499..09da9357 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -35,23 +35,36 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::run(bool do_mint, bool offline_mode) { + static const uint64_t wallet_rpt_idle_work_period_ms = 2000; + m_do_mint = do_mint; if (!offline_mode) { - m_net_server.add_idle_handler([this]() { + m_net_server.add_idle_handler([this]() -> bool + { size_t blocks_fetched = 0; - bool received_money = false; - bool ok; + bool received_money = false, ok = false; std::atomic stop(false); + LOG_PRINT_L2("wallet RPC idle: refreshing..."); m_wallet.refresh(blocks_fetched, received_money, ok, stop); if (stop) + { + LOG_PRINT_L1("wallet RPC idle: refresh failed"); return true; + } if (m_do_mint) + { + bool has_related_alias_in_unconfirmed = false; + LOG_PRINT_L2("wallet RPC idle: scanning tx pool..."); + m_wallet.scan_tx_pool(has_related_alias_in_unconfirmed); + LOG_PRINT_L2("wallet RPC idle: tring to do PoS iteration..."); m_wallet.try_mint_pos(); + } + return true; - }, 2000); + }, wallet_rpt_idle_work_period_ms); } //DO NOT START THIS SERVER IN MORE THEN 1 THREADS WITHOUT REFACTORING