Skip to content

Commit

Permalink
Make sure validating node has voted
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Mar 29, 2024
1 parent 67c4f1d commit a241785
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 4 additions & 8 deletions libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ namespace eosio { namespace testing {

void _start_block(fc::time_point block_time);
signed_block_ptr _finish_block();
void _wait_for_vote_if_needed(controller& c);

// Fields:
protected:
Expand Down Expand Up @@ -626,10 +627,7 @@ namespace eosio { namespace testing {

signed_block_ptr produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
auto sb = _produce_block(skip_time, false);
auto btf = validating_node->create_block_handle_future( sb->calculate_id(), sb );
controller::block_report br;
validating_node->push_block( br, btf.get(), {}, trx_meta_cache_lookup{} );

validate_push_block(sb);
return sb;
}

Expand All @@ -641,15 +639,13 @@ namespace eosio { namespace testing {
auto btf = validating_node->create_block_handle_future( sb->calculate_id(), sb );
controller::block_report br;
validating_node->push_block( br, btf.get(), {}, trx_meta_cache_lookup{} );
_wait_for_vote_if_needed(*validating_node);
}

signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
unapplied_transactions.add_aborted( control->abort_block() );
auto sb = _produce_block(skip_time, true);
auto btf = validating_node->create_block_handle_future( sb->calculate_id(), sb );
controller::block_report br;
validating_node->push_block( br, btf.get(), {}, trx_meta_cache_lookup{} );

validate_push_block(sb);
return sb;
}

Expand Down
12 changes: 8 additions & 4 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,20 @@ namespace eosio { namespace testing {
control->commit_block();
last_produced_block[producer_name] = control->head_block_id();

if (control->head_block()->is_proper_svnn_block()) {
_wait_for_vote_if_needed(*control);

return control->head_block();
}

void base_tester::_wait_for_vote_if_needed(controller& c) {
if (c.head_block()->is_proper_svnn_block()) {
// wait for this node's vote to be processed
size_t retrys = 200;
while (!control->node_has_voted_if_finalizer(control->head_block_id()) && --retrys) {
while (!c.node_has_voted_if_finalizer(c.head_block_id()) && --retrys) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
FC_ASSERT(retrys, "Never saw this nodes vote processed before timeout");
}

return control->head_block();
}

signed_block_ptr base_tester::produce_block( std::vector<transaction_trace_ptr>& traces ) {
Expand Down

0 comments on commit a241785

Please sign in to comment.