protocol: reject claimed block hashes that already are in the chain

This commit is contained in:
moneromooo-monero 2020-12-15 12:50:38 +00:00
parent af0a25544e
commit cf7e1571d3
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
3 changed files with 15 additions and 0 deletions

View file

@ -2548,6 +2548,8 @@ skip:
}
std::unordered_set<crypto::hash> hashes;
uint64_t height = arg.start_height;
const uint64_t blockchain_height = m_core.get_current_blockchain_height();
for (const auto &h: arg.m_block_ids)
{
if (!hashes.insert(h).second)
@ -2556,6 +2558,17 @@ skip:
drop_connection(context, true, false);
return 1;
}
if (height < blockchain_height)
{
const crypto::hash block_in_chain = m_core.get_block_id_by_height(height);
if ((height < context.m_expect_height - 1 && block_in_chain == h) || (height == context.m_expect_height - 1 && block_in_chain != h))
{
LOG_ERROR_CCONTEXT("sent existing block " << h << " at height " << height << ", expected height was " << context.m_expect_height << ", dropping connection");
drop_connection(context, true, false);
return 1;
}
}
++height;
}
uint64_t n_use_blocks = m_core.prevalidate_block_hashes(arg.start_height, arg.m_block_ids, arg.m_block_weights);