Skip to content

Commit 8012ddb

Browse files
Krzysztof Leśniakdnotestein
authored andcommitted
Replace silent if-guard with FC_ASSERT in artifact generation loop
The condition starting_block_num >= target_block_num is guaranteed by all callers and already enforced by FC_ASSERT in block_log.cpp. A silent if-guard would mask bugs by skipping artifact generation entirely; an assert fails loudly so the root cause is immediately visible.
1 parent 57e2148 commit 8012ddb

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

libraries/chain/block_log_artifacts.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -601,42 +601,42 @@ void block_log_artifacts::impl::generate_artifacts_file(const block_log& source_
601601
size_t idx = 0;
602602
uint32_t current_block_number = starting_block_num;
603603

604-
if (starting_block_num >= target_block_num)
604+
FC_ASSERT(starting_block_num >= target_block_num,
605+
"starting_block_num (${s}) must be >= target_block_num (${t})",
606+
("s", starting_block_num)("t", target_block_num));
607+
do
605608
{
606-
do
609+
std::shared_ptr<full_block_with_artifacts> block_with_artifacts;
607610
{
608-
std::shared_ptr<full_block_with_artifacts> block_with_artifacts;
609-
{
610-
std::unique_lock<std::mutex> lock(queue_mutex);
611-
while (!theApp.is_interrupt_request() && !full_block_queue.pop(block_with_artifacts))
612-
queue_condition.wait(lock);
613-
614-
if (theApp.is_interrupt_request() || !block_with_artifacts)
615-
{
616-
ilog("Artifacts file generation interrupted at block: ${current_block_number}", (current_block_number));
617-
generating_interrupted = true;
618-
break;
619-
}
611+
std::unique_lock<std::mutex> lock(queue_mutex);
612+
while (!theApp.is_interrupt_request() && !full_block_queue.pop(block_with_artifacts))
613+
queue_condition.wait(lock);
620614

621-
queue_size.fetch_sub(1, std::memory_order_relaxed);
622-
}
623-
queue_condition.notify_one();
624-
current_block_number = block_with_artifacts->full_block->get_block_num();
625-
store_block_artifacts(current_block_number, block_with_artifacts->block_log_file_pos, block_with_artifacts->attributes, block_with_artifacts->full_block->get_block_id());
626-
627-
if (idx >= BLOCKS_COUNT_INTERVAL_FOR_ARTIFACTS_SAVE)
615+
if (theApp.is_interrupt_request() || !block_with_artifacts)
628616
{
629-
ilog("Artifact generation just processed block ${current_block_number}. Processed blocks count: ${processed_blocks_count}, Target block: ${target_block_num}", (current_block_number)(processed_blocks_count)(target_block_num));
630-
idx = 0;
631-
_header.generating_interrupted_at_block = current_block_number;
632-
flush_header();
617+
ilog("Artifacts file generation interrupted at block: ${current_block_number}", (current_block_number));
618+
generating_interrupted = true;
619+
break;
633620
}
634621

635-
++processed_blocks_count;
636-
++idx;
622+
queue_size.fetch_sub(1, std::memory_order_relaxed);
637623
}
638-
while (current_block_number > target_block_num);
624+
queue_condition.notify_one();
625+
current_block_number = block_with_artifacts->full_block->get_block_num();
626+
store_block_artifacts(current_block_number, block_with_artifacts->block_log_file_pos, block_with_artifacts->attributes, block_with_artifacts->full_block->get_block_id());
627+
628+
if (idx >= BLOCKS_COUNT_INTERVAL_FOR_ARTIFACTS_SAVE)
629+
{
630+
ilog("Artifact generation just processed block ${current_block_number}. Processed blocks count: ${processed_blocks_count}, Target block: ${target_block_num}", (current_block_number)(processed_blocks_count)(target_block_num));
631+
idx = 0;
632+
_header.generating_interrupted_at_block = current_block_number;
633+
flush_header();
634+
}
635+
636+
++processed_blocks_count;
637+
++idx;
639638
}
639+
while (current_block_number > target_block_num);
640640

641641
_header.generating_interrupted_at_block = current_block_number;
642642
});

0 commit comments

Comments
 (0)