SideChain: filter duplicates from missing blocks

pull/271/head
SChernykh 10 months ago
parent e03e7d831e
commit a7f66c8883

@ -1122,7 +1122,7 @@ void P2PServer::download_missing_blocks()
return;
}
std::vector<hash> missing_blocks;
unordered_set<hash> missing_blocks;
m_pool->side_chain().get_missing_blocks(missing_blocks);
if (missing_blocks.empty()) {
@ -1178,7 +1178,7 @@ void P2PServer::download_missing_blocks()
const bool result = send(client,
[&id, client](uint8_t* buf, size_t buf_size) -> size_t
{
LOGINFO(5, "sending BLOCK_REQUEST for id = " << id << " to " << static_cast<char*>(client->m_addrString));
LOGINFO(5, "[download_missing_blocks] sending BLOCK_REQUEST for id = " << id << " to " << static_cast<char*>(client->m_addrString));
if (buf_size < 1 + HASH_SIZE) {
return 0;
@ -2368,7 +2368,7 @@ void P2PServer::P2PClient::on_block_notify(const uint8_t* buf)
const bool result = server->send(this,
[&id, this](uint8_t* buf, size_t buf_size) -> size_t
{
LOGINFO(5, "sending BLOCK_REQUEST for id = " << id << " to " << static_cast<char*>(m_addrString));
LOGINFO(5, "[on_block_notify] sending BLOCK_REQUEST for id = " << id << " to " << static_cast<char*>(m_addrString));
if (buf_size < 1 + HASH_SIZE) {
return 0;
@ -2546,7 +2546,7 @@ void P2PServer::P2PClient::post_handle_incoming_block(const PoolBlock& block, co
const bool result = server->send(this,
[this, &id](uint8_t* buf, size_t buf_size) -> size_t
{
LOGINFO(5, "sending BLOCK_REQUEST for id = " << id << " to " << static_cast<char*>(m_addrString));
LOGINFO(5, "[post_handle_incoming_block] sending BLOCK_REQUEST for id = " << id << " to " << static_cast<char*>(m_addrString));
if (buf_size < 1 + HASH_SIZE) {
return 0;

@ -2088,7 +2088,7 @@ void SideChain::prune_old_blocks()
}
}
void SideChain::get_missing_blocks(std::vector<hash>& missing_blocks) const
void SideChain::get_missing_blocks(unordered_set<hash>& missing_blocks) const
{
missing_blocks.clear();
@ -2100,14 +2100,14 @@ void SideChain::get_missing_blocks(std::vector<hash>& missing_blocks) const
}
if (!b.second->m_parent.empty() && (m_blocksById.find(b.second->m_parent) == m_blocksById.end())) {
missing_blocks.push_back(b.second->m_parent);
missing_blocks.insert(b.second->m_parent);
}
int num_missing_uncles = 0;
for (const hash& h : b.second->m_uncles) {
if (!h.empty() && (m_blocksById.find(h) == m_blocksById.end())) {
missing_blocks.push_back(h);
missing_blocks.insert(h);
// Get no more than 2 first missing uncles at a time from each block
// Blocks with more than 2 uncles are very rare and they will be processed in several steps

@ -52,7 +52,7 @@ public:
bool add_external_block(PoolBlock& block, std::vector<hash>& missing_blocks);
bool add_block(const PoolBlock& block);
void get_missing_blocks(std::vector<hash>& missing_blocks) const;
void get_missing_blocks(unordered_set<hash>& missing_blocks) const;
PoolBlock* find_block(const hash& id) const;
void watch_mainchain_block(const ChainMain& data, const hash& possible_id);

Loading…
Cancel
Save