Skip to content

Commit

Permalink
Fixed block broadcasts
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Dec 23, 2023
1 parent df2a81d commit f7a2a6f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Worker
public:
enum params : int
{
SLOT_SIZE = 1024,
SLOT_SIZE = log::Stream::BUF_SIZE + 1,
BUF_SIZE = SLOT_SIZE * 8192,
};

Expand Down
27 changes: 27 additions & 0 deletions src/p2p_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ void P2PServer::broadcast(const PoolBlock& block, const PoolBlock* parent)

writeVarint(total_reward, data->pruned_blob);
writeVarint(outputs_blob_size, data->pruned_blob);
data->pruned_blob.insert(data->pruned_blob.end(), block.m_sidechainId.h, block.m_sidechainId.h + HASH_SIZE);

data->pruned_blob.insert(data->pruned_blob.end(), mainchain_data.begin() + outputs_offset + outputs_blob_size, mainchain_data.end());

Expand Down Expand Up @@ -890,6 +891,32 @@ void P2PServer::on_broadcast()
return;
}

if (pool_block_debug()) {
for (Broadcast* data : broadcast_queue) {
if (!data->compact_blob.empty()) {
PoolBlock check;
const int result = check.deserialize(data->compact_blob.data(), data->compact_blob.size(), m_pool->side_chain(), nullptr, true);
if (result != 0) {
LOGERR(1, "compact blob broadcast is broken, error " << result);
}
}
{
PoolBlock check;
const int result = check.deserialize(data->pruned_blob.data(), data->pruned_blob.size(), m_pool->side_chain(), nullptr, false);
if (result != 0) {
LOGERR(1, "pruned blob broadcast is broken, error " << result);
}
}
{
PoolBlock check;
const int result = check.deserialize(data->blob.data(), data->blob.size(), m_pool->side_chain(), nullptr, false);
if (result != 0) {
LOGERR(1, "full blob broadcast is broken, error " << result);
}
}
}
}

for (P2PClient* client = static_cast<P2PClient*>(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast<P2PClient*>(client->m_next)) {
if (!client->is_good()) {
continue;
Expand Down
14 changes: 12 additions & 2 deletions src/pool_block_parser.inl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si

outputs_blob_size = static_cast<int>(data - data_begin) - outputs_offset;
outputs_blob.assign(data_begin + outputs_offset, data);

m_sidechainId.clear();
}
else {
// Outputs are not in the buffer and must be calculated from sidechain data
Expand All @@ -144,6 +146,9 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
}

outputs_blob_size = static_cast<int>(tmp);

// Required by sidechain.get_outputs_blob() to speed up repeated broadcasts from different peers
READ_BUF(m_sidechainId.h, HASH_SIZE);
}

// Technically some p2pool node could keep stuffing block with transactions until reward is less than 0.6 XMR
Expand Down Expand Up @@ -415,6 +420,13 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
},
static_cast<int>(size + outputs_blob_size_diff + transactions_blob_size_diff + consensus_id.size()), check.h, HASH_SIZE);

if (m_sidechainId.empty()) {
m_sidechainId = check;
}
else if (m_sidechainId != check) {
return __LINE__;
}

#if POOL_BLOCK_DEBUG
m_sideChainDataDebug.assign(sidechain_data_begin, data_end);
#endif
Expand All @@ -424,8 +436,6 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
if (!verify_merkle_proof(check, m_merkleProof, mm_aux_slot, mm_n_aux_chains, m_merkleRoot)) {
return __LINE__;
}

m_sidechainId = check;
}
catch (std::exception& e) {
LOGERR(0, "Exception in PoolBlock::deserialize(): " << e.what());
Expand Down

0 comments on commit f7a2a6f

Please sign in to comment.