Don't send the same Monero block broadcast to peers who sent it already
This commit is contained in:
@@ -1712,13 +1712,19 @@ void P2PServer::broadcast_monero_block(const uint8_t* data, uint32_t data_size,
|
||||
return;
|
||||
}
|
||||
|
||||
if (!duplicate_check_done && !store_monero_block_broadcast(data + sizeof(MoneroBlockBroadcastHeader), data_size - sizeof(MoneroBlockBroadcastHeader))) {
|
||||
hash digest;
|
||||
sha256(data + sizeof(MoneroBlockBroadcastHeader), data_size - sizeof(MoneroBlockBroadcastHeader), digest.h);
|
||||
|
||||
if (!duplicate_check_done && !store_monero_block_broadcast(digest)) {
|
||||
LOGINFO(6, "broadcast_monero_block: skipping duplicate broadcast");
|
||||
return;
|
||||
}
|
||||
|
||||
for (P2PClient* client = static_cast<P2PClient*>(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast<P2PClient*>(client->m_next)) {
|
||||
if ((source && (client == source)) || !client->is_good() || (client->m_protocolVersion < PROTOCOL_VERSION_1_4)) {
|
||||
if ((source && (client == source)) ||
|
||||
!client->is_good() ||
|
||||
(client->m_protocolVersion < PROTOCOL_VERSION_1_4) ||
|
||||
(client->m_lastMoneroBlockBroadcastDigest == digest)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1749,11 +1755,8 @@ void P2PServer::broadcast_monero_block(const uint8_t* data, uint32_t data_size,
|
||||
}
|
||||
}
|
||||
|
||||
bool P2PServer::store_monero_block_broadcast(const uint8_t* data, uint32_t data_size)
|
||||
bool P2PServer::store_monero_block_broadcast(const hash& digest)
|
||||
{
|
||||
hash digest;
|
||||
sha256(data, data_size, digest.h);
|
||||
|
||||
// Every message can be received from multiple peers, so broadcast it only once
|
||||
MutexLock lock(m_MoneroBlockBroadcastsLock);
|
||||
return m_MoneroBlockBroadcasts.emplace(*digest.u64(), seconds_since_epoch()).second;
|
||||
@@ -3069,8 +3072,10 @@ bool P2PServer::P2PClient::on_monero_block_broadcast(const uint8_t* buf, uint32_
|
||||
return true;
|
||||
}
|
||||
|
||||
sha256(buf, size, m_lastMoneroBlockBroadcastDigest.h);
|
||||
|
||||
// Ignore repeated old messages
|
||||
if (!server->store_monero_block_broadcast(buf, size)) {
|
||||
if (!server->store_monero_block_broadcast(m_lastMoneroBlockBroadcastDigest)) {
|
||||
LOGINFO(6, "Repeated MONERO_BLOCK_BROADCAST - ignored");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -162,6 +162,8 @@ public:
|
||||
hash m_broadcastedHashes[8];
|
||||
uint32_t m_broadcastedHashesIndex;
|
||||
|
||||
hash m_lastMoneroBlockBroadcastDigest;
|
||||
|
||||
// log::Stream wrapper
|
||||
struct SoftwareDisplayName
|
||||
{
|
||||
@@ -220,7 +222,7 @@ public:
|
||||
void broadcast_monero_block_handler();
|
||||
void broadcast_monero_block(const uint8_t* data, uint32_t data_size, const P2PClient* source, bool duplicate_check_done);
|
||||
|
||||
bool store_monero_block_broadcast(const uint8_t* data, uint32_t data_size);
|
||||
bool store_monero_block_broadcast(const hash& digest);
|
||||
|
||||
private:
|
||||
[[nodiscard]] const char* get_log_category() const override;
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "keccak.h"
|
||||
#include "merkle.h"
|
||||
#include "merge_mining_client.h"
|
||||
#include "sha256.h"
|
||||
|
||||
#ifdef WITH_TLS
|
||||
#include <openssl/curve25519.h>
|
||||
@@ -1146,7 +1147,10 @@ void p2pool::submit_block() const
|
||||
}
|
||||
request.append("\"]}");
|
||||
|
||||
m_p2pServer->store_monero_block_broadcast(blob.data(), static_cast<uint32_t>(blob.size()));
|
||||
hash digest;
|
||||
sha256(blob.data(), static_cast<uint32_t>(blob.size()), digest.h);
|
||||
|
||||
m_p2pServer->store_monero_block_broadcast(digest);
|
||||
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user