1616
1717 Copyright 2017-2020 Telegram Systems LLP
1818*/
19- #include " validator-session.hpp"
2019#include " td/utils/Random.h"
21- #include " candidate-serializer.h"
22- #include " delay.h"
2320#include " td/utils/overloaded.h"
2421#include " ton/ton-tl.hpp"
2522
23+ #include " candidate-serializer.h"
24+ #include " delay.h"
25+ #include " validator-session.hpp"
26+
2627namespace ton {
2728
2829namespace validatorsession {
@@ -209,7 +210,7 @@ void ValidatorSessionImpl::preprocess_block(catchain::CatChainBlock *block) {
209210}
210211
211212bool ValidatorSessionImpl::ensure_candidate_unique (td::uint32 src_idx, td::uint32 round,
212- ValidatorSessionCandidateId block_id) {
213+ ValidatorSessionCandidateId block_id) {
213214 auto it = src_round_candidate_[src_idx].find (round);
214215 if (it != src_round_candidate_[src_idx].end () && it->second != block_id) {
215216 VLOG (VALIDATOR_SESSION_WARNING) << this << " [node " << description_->get_source_adnl_id (src_idx) << " ][candidate "
@@ -770,8 +771,8 @@ void ValidatorSessionImpl::try_approve_block(const SentBlock *block) {
770771 td::actor::send_closure (SelfId, &ValidatorSessionImpl::candidate_decision_ok, round, hash, root_hash,
771772 file_hash, src, R.ok_from (), timer.elapsed (), R.is_cached ());
772773 } else {
773- td::actor::send_closure (SelfId, &ValidatorSessionImpl::candidate_decision_fail, round, hash, R.reason (),
774- src, R.proof (), timer.elapsed (), R.is_cached ());
774+ td::actor::send_closure (SelfId, &ValidatorSessionImpl::candidate_decision_fail, round, hash, R.reason (), src,
775+ R.proof (), timer.elapsed (), R.is_cached ());
775776 }
776777 });
777778 pending_approve_.insert (block_id);
@@ -1045,7 +1046,6 @@ void ValidatorSessionImpl::store_block_candidate(ValidatorSessionCandidateId can
10451046 }
10461047}
10471048
1048-
10491049void ValidatorSessionImpl::request_new_block (bool now) {
10501050 if (requested_new_block_now_) {
10511051 return ;
@@ -1269,9 +1269,9 @@ void ValidatorSessionImpl::start() {
12691269
12701270 auto w = description ().export_catchain_nodes ();
12711271
1272- catchain_ = catchain::CatChain::create (
1273- make_catchain_callback (), description (). opts (). catchain_opts , keyring_, adnl_, overlay_manager_, std::move (w),
1274- local_id (), unique_hash_, db_root_, db_suffix_, allow_unsafe_self_blocks_resync_);
1272+ catchain_ = catchain::CatChain::create (make_catchain_callback (), description (). opts (). catchain_opts , keyring_, adnl_,
1273+ overlay_manager_, std::move (w), local_id (), unique_hash_, db_root_, db_suffix_ ,
1274+ allow_unsafe_self_blocks_resync_);
12751275
12761276 check_all ();
12771277}
@@ -1408,14 +1408,14 @@ void ValidatorSessionImpl::stats_init() {
14081408 cur_stats_.total_weight = description ().get_total_weight ();
14091409 cur_stats_.self = description ().get_source_id (local_idx ());
14101410
1411- for (auto it = stats_pending_approve_.begin (); it != stats_pending_approve_.end (); ) {
1411+ for (auto it = stats_pending_approve_.begin (); it != stats_pending_approve_.end ();) {
14121412 if (it->first .first < cur_round_) {
14131413 it = stats_pending_approve_.erase (it);
14141414 } else {
14151415 ++it;
14161416 }
14171417 }
1418- for (auto it = stats_pending_sign_.begin (); it != stats_pending_sign_.end (); ) {
1418+ for (auto it = stats_pending_sign_.begin (); it != stats_pending_sign_.end ();) {
14191419 if (it->first .first < cur_round_) {
14201420 it = stats_pending_sign_.erase (it);
14211421 } else {
@@ -1433,7 +1433,7 @@ void ValidatorSessionImpl::stats_init() {
14331433void ValidatorSessionImpl::stats_add_round () {
14341434 td::uint32 round = cur_stats_.first_round + cur_stats_.rounds .size ();
14351435 cur_stats_.rounds .emplace_back ();
1436- auto & stat = cur_stats_.rounds .back ();
1436+ auto & stat = cur_stats_.rounds .back ();
14371437 stat.producers .resize (description ().get_max_priority () + 1 );
14381438 for (td::uint32 i = 0 ; i < description ().get_total_nodes (); i++) {
14391439 td::int32 priority = description ().get_node_priority (i, round);
@@ -1502,38 +1502,38 @@ ValidatorSessionStats::Producer *ValidatorSessionImpl::stats_get_candidate_stat_
15021502}
15031503
15041504void ValidatorSessionImpl::stats_process_action (td::uint32 node_id, ton_api::validatorSession_round_Message &action) {
1505- ton_api::downcast_call (action, td::overloaded (
1506- [&]( const ton_api::validatorSession_message_submittedBlock &obj) {
1507- auto candidate_id = description (). candidate_id (
1508- node_id, obj. root_hash_ , obj. file_hash_ , obj. collated_data_file_hash_ );
1509- auto stat = stats_get_candidate_stat (
1510- obj. round_ , description ().get_source_id (node_id), candidate_id );
1511- if ( stat && stat-> got_submit_at <= 0.0 ) {
1512- stat->got_submit_at = td::Clocks::system ();
1513- stat->block_id . root_hash = obj. root_hash_ ;
1514- stat->block_id .file_hash = obj.file_hash_ ;
1515- stat->collated_data_hash = obj.collated_data_file_hash_ ;
1516- }
1517- },
1518- [&]( const ton_api::validatorSession_message_approvedBlock &obj) {
1519- if (obj. candidate_ == skip_round_candidate_id () ) {
1520- return ;
1521- }
1522- process_approve (node_id, obj. round_ , obj. candidate_ );
1523- },
1524- [&]( const ton_api::validatorSession_message_commit &obj) {
1525- if (obj. candidate_ == skip_round_candidate_id () ) {
1526- return ;
1527- }
1528- auto stat = stats_get_candidate_stat_by_id (obj. round_ , obj. candidate_ );
1529- if (stat) {
1530- stat-> set_signed_by (node_id, description (). get_node_weight (node_id),
1531- description ().get_total_weight ());
1532- } else {
1533- stats_pending_sign_[{obj.round_ , obj.candidate_ }].push_back (node_id);
1534- }
1535- },
1536- [](const auto &) {}));
1505+ ton_api::downcast_call (
1506+ action,
1507+ td::overloaded (
1508+ [&]( const ton_api::validatorSession_message_submittedBlock & obj) {
1509+ auto candidate_id =
1510+ description ().candidate_id (node_id, obj. root_hash_ , obj. file_hash_ , obj. collated_data_file_hash_ );
1511+ auto stat = stats_get_candidate_stat (obj. round_ , description (). get_source_id (node_id), candidate_id);
1512+ if (stat && stat->got_submit_at <= 0.0 ) {
1513+ stat->got_submit_at = td::Clocks::system () ;
1514+ stat->block_id .root_hash = obj.root_hash_ ;
1515+ stat->block_id . file_hash = obj.file_hash_ ;
1516+ stat-> collated_data_hash = obj. collated_data_file_hash_ ;
1517+ }
1518+ },
1519+ [&]( const ton_api::validatorSession_message_approvedBlock &obj ) {
1520+ if (obj. candidate_ == skip_round_candidate_id ()) {
1521+ return ;
1522+ }
1523+ process_approve (node_id, obj. round_ , obj. candidate_ );
1524+ },
1525+ [&]( const ton_api::validatorSession_message_commit &obj ) {
1526+ if (obj. candidate_ == skip_round_candidate_id ()) {
1527+ return ;
1528+ }
1529+ auto stat = stats_get_candidate_stat_by_id (obj. round_ , obj. candidate_ );
1530+ if (stat) {
1531+ stat-> set_signed_by (node_id, description (). get_node_weight (node_id), description ().get_total_weight ());
1532+ } else {
1533+ stats_pending_sign_[{obj.round_ , obj.candidate_ }].push_back (node_id);
1534+ }
1535+ },
1536+ [](const auto &) {}));
15371537}
15381538
15391539void ValidatorSessionImpl::process_approve (td::uint32 node_id, td::uint32 round,
0 commit comments