diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 956c94c..771814a 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -913,6 +913,11 @@ bool P2PServer::P2PClient::on_read(char* data, uint32_t size) } void P2PServer::P2PClient::on_read_failed(int /*err*/) +{ + on_disconnected(); +} + +void P2PServer::P2PClient::on_disconnected() { if (!m_handshakeComplete) { LOGWARN(5, "peer " << static_cast(m_addrString) << " disconnected before finishing handshake"); diff --git a/src/p2p_server.h b/src/p2p_server.h index 04b6c90..e75bfe5 100644 --- a/src/p2p_server.h +++ b/src/p2p_server.h @@ -64,6 +64,7 @@ public: bool on_connect() override; bool on_read(char* data, uint32_t size) override; void on_read_failed(int err) override; + void on_disconnected() override; // Both peers send handshake challenge immediately after a connection is established // Both peers must have the same consensus ID for handshake to succeed diff --git a/src/side_chain.cpp b/src/side_chain.cpp index e69730e..89588ea 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -634,6 +634,9 @@ void SideChain::print_status() uint64_t total_orphans = 0; uint64_t our_orphans = 0; + uint64_t your_reward = 0; + uint64_t total_reward = 0; + if (m_chainTip) { std::sort(blocks_in_window.begin(), blocks_in_window.end()); for (uint64_t i = 0; (i < m_chainWindowSize) && (i <= tip_height); ++i) { @@ -647,25 +650,23 @@ void SideChain::print_status() } } } - } - - const uint64_t block_reward = m_pool->block_template().final_reward(); - uint64_t reward_share = 0; - if (m_chainTip) { Wallet w = m_pool->params().m_wallet; + const std::vector& outs = m_chainTip->m_outputs; + hash eph_public_key; - for (size_t i = 0, n = m_chainTip->m_outputs.size(); i < n; ++i) { - if (w.get_eph_public_key(m_chainTip->m_txkeySec, i, eph_public_key) && (m_chainTip->m_outputs[i].m_ephPublicKey == eph_public_key)) { - reward_share = m_chainTip->m_outputs[i].m_reward; - break; + for (size_t i = 0, n = outs.size(); i < n; ++i) { + if (w.get_eph_public_key(m_chainTip->m_txkeySec, i, eph_public_key) && (outs[i].m_ephPublicKey == eph_public_key)) { + your_reward = outs[i].m_reward; } + total_reward += outs[i].m_reward; } } uint64_t product[2]; - product[0] = umul128(pool_hashrate, reward_share, &product[1]); - const uint64_t hashrate_est = udiv128(product[1], product[0], block_reward, &rem); + product[0] = umul128(pool_hashrate, your_reward, &product[1]); + const uint64_t hashrate_est = total_reward ? udiv128(product[1], product[0], total_reward, &rem) : 0; + const double block_share = total_reward ? ((static_cast(your_reward) * 100.0) / static_cast(total_reward)) : 0.0; LOGINFO(0, "status" << "\nMain chain height = " << m_pool->block_template().height() << @@ -675,7 +676,7 @@ void SideChain::print_status() (hashrate_est ? "\nYour hashrate (pool-side) = " : "") << (hashrate_est ? log::Hashrate(hashrate_est) : log::Hashrate()) << "\nPPLNS window = " << total_blocks_in_window << " blocks (+" << total_uncles_in_window << " uncles, " << total_orphans << " orphans)" "\nYour shares = " << our_blocks_in_window << " blocks (+" << our_uncles_in_window << " uncles, " << our_orphans << " orphans)" - "\nBlock reward share (est) = " << log::XMRAmount(reward_share) + "\nBlock reward share = " << block_share << "% (" << log::XMRAmount(your_reward) << ')' ); } diff --git a/src/tcp_server.h b/src/tcp_server.h index 997378d..4c12dd6 100644 --- a/src/tcp_server.h +++ b/src/tcp_server.h @@ -90,6 +90,7 @@ public: virtual bool on_connect() = 0; virtual bool on_read(char* data, uint32_t size) = 0; virtual void on_read_failed(int /*err*/) {} + virtual void on_disconnected() {} static void on_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf); diff --git a/src/tcp_server.inl b/src/tcp_server.inl index 4913ee8..6ecc1b3 100644 --- a/src/tcp_server.inl +++ b/src/tcp_server.inl @@ -839,6 +839,9 @@ void TCPServer::Client::on_read(uv_stream_t* stre LOGWARN(5, "client " << static_cast(pThis->m_addrString) << " failed to read response, err = " << uv_err_name(err)); pThis->on_read_failed(err); } + else { + pThis->on_disconnected(); + } pThis->close(); } }