Skip to content

Commit

Permalink
GH-1941 Add head_block_timestamp()
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Dec 21, 2023
1 parent e012dc1 commit bc2ff35
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3524,6 +3524,9 @@ void controller::set_disable_replay_opts( bool v ) {
uint32_t controller::head_block_num()const {
return my->head->block_num();
}
block_timestamp_type controller::head_block_timestamp()const {
return my->head->header.timestamp;
}
time_point controller::head_block_time()const {
return my->head->header.timestamp;
}
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ namespace eosio::chain {

uint32_t head_block_num()const;
time_point head_block_time()const;
block_timestamp_type head_block_timestamp()const;
block_id_type head_block_id()const;
account_name head_block_producer()const;
const block_header& head_block_header()const;
Expand Down
6 changes: 3 additions & 3 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,8 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
handle_error(fc::std_exception_wrapper::from_current_exception(e));
}

const auto& hb = chain.head_block();
now = fc::time_point::now();
if (hb && hb->timestamp.next().to_time_point() >= now) {
if (chain.head_block_timestamp().next().to_time_point() >= now) {
_production_enabled = true;
}

Expand All @@ -748,7 +747,8 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
("net", br.total_net_usage)("cpu", br.total_cpu_usage_us)
("elapsed", br.total_elapsed_time)("time", br.total_time)("latency", (now - block->timestamp).count() / 1000));
const auto& hb_id = chain.head_block_id();
if (chain.get_read_mode() != db_read_mode::IRREVERSIBLE && hb_id != id && hb != nullptr) { // not applied to head
const auto& hb = chain.head_block();
if (chain.get_read_mode() != db_read_mode::IRREVERSIBLE && hb && hb_id != id && hb != nullptr) { // not applied to head
ilog("Block not applied to head ${id}... #${n} @ ${t} signed by ${p} "
"[trxs: ${count}, lib: ${lib}, net: ${net}, cpu: ${cpu}, elapsed: ${elapsed}, time: ${time}, latency: ${latency} ms]",
("p", hb->producer)("id", hb_id.str().substr(8, 16))("n", hb->block_num())("t", hb->timestamp)
Expand Down

0 comments on commit bc2ff35

Please sign in to comment.