1
0
Fork 0
forked from lthn/blockchain

simplewallet: PoS mining in RPC mode made more kind to another wallet's instances (tx pool awareness, ZANO-385

This commit is contained in:
sowle 2019-06-27 02:30:43 +03:00
parent 606b2ffc2c
commit 22bbb59117
3 changed files with 25 additions and 13 deletions

View file

@ -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);

View file

@ -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<bool> 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;
}

View file

@ -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<bool> 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