Skip to content

Commit

Permalink
GH-1837 Use full cpu effort for calculated wake up time for producer
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Oct 31, 2023
1 parent 4a9dd03 commit 1dac3fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2495,7 +2495,7 @@ void producer_plugin_impl::schedule_production_loop() {
chain::controller& chain = chain_plug->chain();
fc_dlog(_log, "Speculative Block Created; Scheduling Speculative/Production Change");
EOS_ASSERT(chain.is_building_block(), missing_pending_block_state, "speculating without pending_block_state");
auto wake_time = block_timing_util::calculate_producer_wake_up_time(_produce_block_cpu_effort, chain.pending_block_num(), chain.pending_block_timestamp(),
auto wake_time = block_timing_util::calculate_producer_wake_up_time(fc::microseconds{config::block_interval_us}, chain.pending_block_num(), chain.pending_block_timestamp(),
_producers, chain.head_block_state()->active_schedule.producers,
_producer_watermarks);
schedule_delayed_production_loop(weak_from_this(), wake_time);
Expand Down
18 changes: 18 additions & 0 deletions plugins/producer_plugin/test/test_block_timing_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,24 @@ BOOST_AUTO_TEST_CASE(test_calculate_producer_wake_up_time) {
expected_block_time = block_timestamp_type(prod_round_1st_block_slot + 2*config::producer_repetitions + 2).to_time_point(); // with watermark, wait until next
BOOST_CHECK_EQUAL(calculate_producer_wake_up_time(full_cpu_effort, 2, block_timestamp, producers, active_schedule, prod_watermarks), expected_block_time);
}
{ // actual example that caused multiple start blocks
producer_watermarks prod_watermarks;
std::set<account_name> producers = {
"inita"_n, "initb"_n, "initc"_n, "initd"_n, "inite"_n, "initf"_n, "initg"_n, "p1"_n,
"inith"_n, "initi"_n, "initj"_n, "initk"_n, "initl"_n, "initm"_n, "initn"_n,
"inito"_n, "initp"_n, "initq"_n, "initr"_n, "inits"_n, "initt"_n, "initu"_n, "p2"_n
};
std::vector<chain::producer_authority> active_schedule{
{"inita"_n}, {"initb"_n}, {"initc"_n}, {"initd"_n}, {"inite"_n}, {"initf"_n}, {"initg"_n},
{"inith"_n}, {"initi"_n}, {"initj"_n}, {"initk"_n}, {"initl"_n}, {"initm"_n}, {"initn"_n},
{"inito"_n}, {"initp"_n}, {"initq"_n}, {"initr"_n}, {"inits"_n}, {"initt"_n}, {"initu"_n}
};
auto default_cpu_effort = fc::microseconds(block_interval.count() - (450000/12)); // 462,500
auto wake_time = calculate_producer_wake_up_time(default_cpu_effort, 106022362, eosio::chain::block_timestamp_type(fc::time_point::from_iso_string("2023-10-31T16:06:41.000")),
producers, active_schedule, prod_watermarks);
BOOST_REQUIRE(!!wake_time);
BOOST_CHECK_EQUAL(wake_time->to_iso_string(), fc::time_point::from_iso_string("2023-10-31T16:06:40.587").to_iso_string());
}

}

Expand Down

0 comments on commit 1dac3fb

Please sign in to comment.