aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_protocol/block_queue.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-08-18 20:14:23 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-08-21 21:57:19 +0100
commit70b8c6d77a6aaf90a6e84f3ec6f25bea3b163c40 (patch)
treed533e90a67366fd3a6778bb6f3da82bbe0a7d326 /src/cryptonote_protocol/block_queue.cpp
parentMerge pull request #2303 (diff)
downloadmonero-70b8c6d77a6aaf90a6e84f3ec6f25bea3b163c40.tar.xz
cryptonote_protocol: misc fixes to the new sync algorithm
Fix sync wedge corner case: It could happen if a connection went into standby mode, while it was the one which had requested the next span, and that span was still waiting for the data, and that peer is not on the main chain. Other peers can then start asking for that data again and again, but never get it as only that forked peer does. And various other fixes
Diffstat (limited to 'src/cryptonote_protocol/block_queue.cpp')
-rw-r--r--src/cryptonote_protocol/block_queue.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/cryptonote_protocol/block_queue.cpp b/src/cryptonote_protocol/block_queue.cpp
index 94d31404e..02a8e3ec2 100644
--- a/src/cryptonote_protocol/block_queue.cpp
+++ b/src/cryptonote_protocol/block_queue.cpp
@@ -52,8 +52,11 @@ namespace cryptonote
void block_queue::add_blocks(uint64_t height, std::list<cryptonote::block_complete_entry> bcel, const boost::uuids::uuid &connection_id, float rate, size_t size)
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
- remove_span(height);
+ std::list<crypto::hash> hashes;
+ bool has_hashes = remove_span(height, &hashes);
blocks.insert(span(height, std::move(bcel), connection_id, rate, size));
+ if (has_hashes)
+ set_span_hashes(height, connection_id, hashes);
}
void block_queue::add_blocks(uint64_t height, uint64_t nblocks, const boost::uuids::uuid &connection_id, boost::posix_time::ptime time)
@@ -92,17 +95,20 @@ void block_queue::flush_stale_spans(const std::set<boost::uuids::uuid> &live_con
}
}
-void block_queue::remove_span(uint64_t start_block_height)
+bool block_queue::remove_span(uint64_t start_block_height, std::list<crypto::hash> *hashes)
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);
for (block_map::iterator i = blocks.begin(); i != blocks.end(); ++i)
{
if (i->start_block_height == start_block_height)
{
+ if (hashes)
+ *hashes = std::move(i->hashes);
blocks.erase(i);
- return;
+ return true;
}
}
+ return false;
}
void block_queue::remove_spans(const boost::uuids::uuid &connection_id, uint64_t start_block_height)
@@ -278,6 +284,22 @@ bool block_queue::get_next_span(uint64_t &height, std::list<cryptonote::block_co
return false;
}
+bool block_queue::has_next_span(const boost::uuids::uuid &connection_id, bool &filled) const
+{
+ boost::unique_lock<boost::recursive_mutex> lock(mutex);
+ if (blocks.empty())
+ return false;
+ block_map::const_iterator i = blocks.begin();
+ if (is_blockchain_placeholder(*i))
+ ++i;
+ if (i == blocks.end())
+ return false;
+ if (i->connection_id != connection_id)
+ return false;
+ filled = !i->blocks.empty();
+ return true;
+}
+
size_t block_queue::get_data_size() const
{
boost::unique_lock<boost::recursive_mutex> lock(mutex);