aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl49
1 files changed, 17 insertions, 32 deletions
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index 5216b0d6e..6c36a3b5b 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -1475,14 +1475,28 @@ namespace cryptonote
return 1;
}
+ bool stopped = false;
+ auto cleanup_on_exit = epee::misc_utils::create_scope_leave_handler([this, &stopped, &context, span_connection_id, start_height]() {
+ if (!m_core.cleanup_handle_incoming_blocks())
+ {
+ LOG_PRINT_CCONTEXT_L0("Failure in cleanup_handle_incoming_blocks");
+ return;
+ }
+
+ if (stopped)
+ return;
+
+ m_block_queue.remove_spans(span_connection_id, start_height);
+ });
+
uint64_t block_process_time_full = 0, transactions_process_time_full = 0;
size_t num_txs = 0, blockidx = 0;
for(const block_complete_entry& block_entry: blocks)
{
if (m_stopping)
{
- m_core.cleanup_handle_incoming_blocks();
- return 1;
+ stopped = true;
+ return 1;
}
// process transactions
@@ -1501,13 +1515,6 @@ namespace cryptonote
}))
LOG_ERROR_CCONTEXT("span connection id not found");
- if (!m_core.cleanup_handle_incoming_blocks())
- {
- LOG_PRINT_CCONTEXT_L0("Failure in cleanup_handle_incoming_blocks");
- return 1;
- }
- // in case the peer had dropped beforehand, remove the span anyway so other threads can wake up and get it
- m_block_queue.remove_spans(span_connection_id, start_height);
return 1;
}
TIME_MEASURE_FINISH(transactions_process_time);
@@ -1534,14 +1541,6 @@ namespace cryptonote
}))
LOG_ERROR_CCONTEXT("span connection id not found");
- if (!m_core.cleanup_handle_incoming_blocks())
- {
- LOG_PRINT_CCONTEXT_L0("Failure in cleanup_handle_incoming_blocks");
- return 1;
- }
-
- // in case the peer had dropped beforehand, remove the span anyway so other threads can wake up and get it
- m_block_queue.remove_spans(span_connection_id, start_height);
return 1;
}
if(bvc.m_marked_as_orphaned)
@@ -1554,14 +1553,6 @@ namespace cryptonote
}))
LOG_ERROR_CCONTEXT("span connection id not found");
- if (!m_core.cleanup_handle_incoming_blocks())
- {
- LOG_PRINT_CCONTEXT_L0("Failure in cleanup_handle_incoming_blocks");
- return 1;
- }
-
- // in case the peer had dropped beforehand, remove the span anyway so other threads can wake up and get it
- m_block_queue.remove_spans(span_connection_id, start_height);
return 1;
}
@@ -1573,13 +1564,7 @@ namespace cryptonote
MDEBUG(context << "Block process time (" << blocks.size() << " blocks, " << num_txs << " txs): " << block_process_time_full + transactions_process_time_full << " (" << transactions_process_time_full << "/" << block_process_time_full << ") ms");
- if (!m_core.cleanup_handle_incoming_blocks())
- {
- LOG_PRINT_CCONTEXT_L0("Failure in cleanup_handle_incoming_blocks");
- return 1;
- }
-
- m_block_queue.remove_spans(span_connection_id, start_height);
+ cleanup_on_exit.reset();
const uint64_t current_blockchain_height = m_core.get_current_blockchain_height();
if (current_blockchain_height > previous_height)