Skip to content

Commit 5c907d3

Browse files
author
sech1
committed
Fix: submit broadcasted Monero blocks one at a time
1 parent 6d3fbc5 commit 5c907d3

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

src/p2p_server.cpp

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,42 @@ void P2PServer::clean_monero_block_broadcasts()
16351635
}
16361636
}
16371637

1638+
void P2PServer::submit_monero_blocks()
1639+
{
1640+
if (m_MoneroBlocksToSubmit.empty()) {
1641+
return;
1642+
}
1643+
1644+
LOGINFO(6, "submit_monero_blocks: started, queue size = " << m_MoneroBlocksToSubmit.size());
1645+
1646+
const Params::Host& host = m_pool->current_host();
1647+
1648+
JSONRPCRequest::call(
1649+
host.m_address,
1650+
host.m_rpcPort,
1651+
m_MoneroBlocksToSubmit.front(),
1652+
host.m_rpcLogin,
1653+
m_socks5Proxy,
1654+
host.m_rpcSSL,
1655+
host.m_rpcSSL_Fingerprint,
1656+
JSONRPCRequest::dummy_callback,
1657+
[this](const char* data, size_t size, double)
1658+
{
1659+
if (size > 0) {
1660+
LOGERR(3, "on_monero_block_broadcast: submit_block RPC request failed, error " << log::const_buf(data, size));
1661+
}
1662+
1663+
if (!m_MoneroBlocksToSubmit.empty()) {
1664+
m_MoneroBlocksToSubmit.pop_front();
1665+
}
1666+
LOGINFO(6, "submit_monero_blocks: finished, queue size = " << m_MoneroBlocksToSubmit.size());
1667+
1668+
submit_monero_blocks();
1669+
},
1670+
&m_loop
1671+
);
1672+
}
1673+
16381674
void P2PServer::broadcast_monero_block_async(std::vector<std::vector<uint8_t>>&& blobs)
16391675
{
16401676
MutexLock lock(m_MoneroBlocksToBroadcastLock);
@@ -3099,25 +3135,13 @@ bool P2PServer::P2PClient::on_monero_block_broadcast(const uint8_t* buf, uint32_
30993135

31003136
request.append("\"]}");
31013137

3102-
const Params::Host& host = pool->current_host();
3138+
server->m_MoneroBlocksToSubmit.emplace_back(std::move(request));
31033139

3104-
JSONRPCRequest::call(
3105-
host.m_address,
3106-
host.m_rpcPort,
3107-
request,
3108-
host.m_rpcLogin,
3109-
server->m_socks5Proxy,
3110-
host.m_rpcSSL,
3111-
host.m_rpcSSL_Fingerprint,
3112-
JSONRPCRequest::dummy_callback,
3113-
[](const char* data, size_t size, double)
3114-
{
3115-
if (size > 0) {
3116-
LOGERR(3, "on_monero_block_broadcast: submit_block RPC request failed, error " << log::const_buf(data, size));
3117-
}
3118-
},
3119-
&server->m_loop
3120-
);
3140+
// Kick the JSON RPC request loop only when the first request arrives
3141+
// The other requests will be queued and submit_monero_blocks() will process them one by one
3142+
if (server->m_MoneroBlocksToSubmit.size() == 1) {
3143+
server->submit_monero_blocks();
3144+
}
31213145

31223146
return true;
31233147
}

src/p2p_server.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,12 @@ class P2PServer : public TCPServer
352352

353353
uv_async_t m_MoneroBlocksToBroadcastAsync;
354354

355+
std::deque<std::string> m_MoneroBlocksToSubmit;
356+
355357
static void on_monero_block_broadcast(uv_async_t* handle) { reinterpret_cast<P2PServer*>(handle->data)->broadcast_monero_block_handler(); }
356358

357359
void clean_monero_block_broadcasts();
360+
void submit_monero_blocks();
358361
};
359362

360363
} // namespace p2pool

0 commit comments

Comments
 (0)