Skip to content

Commit

Permalink
Fix block limit classification
Browse files Browse the repository at this point in the history
Block size estimation can decrease, so it was possible that soft limit was reached, but the block is not considered overloaded
  • Loading branch information
SpyCheese committed Oct 30, 2024
1 parent 0862cca commit 90819bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions validator/impl/collator-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class Collator final : public td::actor::Actor {
td::RefInt256 masterchain_create_fee_, basechain_create_fee_;
std::unique_ptr<block::BlockLimits> block_limits_;
std::unique_ptr<block::BlockLimitStatus> block_limit_status_;
int block_limit_class_ = 0;
ton::LogicalTime min_new_msg_lt{std::numeric_limits<td::uint64>::max()};
block::CurrencyCollection total_balance_, old_total_balance_, total_validator_fees_;
block::CurrencyCollection global_balance_, old_global_balance_, import_created_{0};
Expand Down
16 changes: 11 additions & 5 deletions validator/impl/collator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,7 @@ bool Collator::out_msg_queue_cleanup() {
register_out_msg_queue_op();
if (!block_limit_status_->fits(block::ParamLimits::cl_normal)) {
block_full_ = true;
block_limit_class_ = std::max(block_limit_class_, block_limit_status_->classify());
}
}
return !delivered;
Expand Down Expand Up @@ -2402,6 +2403,7 @@ bool Collator::out_msg_queue_cleanup() {
register_out_msg_queue_op();
if (!block_limit_status_->fits(block::ParamLimits::cl_normal)) {
block_full_ = true;
block_limit_class_ = std::max(block_limit_class_, block_limit_status_->classify());
}
queue.next();
++i;
Expand Down Expand Up @@ -3205,6 +3207,7 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R
// 7. check whether the block is full now
if (!block_limit_status_->fits(block::ParamLimits::cl_normal)) {
block_full_ = true;
block_limit_class_ = std::max(block_limit_class_, block_limit_status_->classify());
return 3;
}
if (soft_timeout_.is_in_past(td::Timestamp::now())) {
Expand Down Expand Up @@ -3568,6 +3571,7 @@ bool Collator::process_inbound_internal_messages() {
block_full_ = !block_limit_status_->fits(block::ParamLimits::cl_normal);
if (block_full_) {
LOG(INFO) << "BLOCK FULL, stop processing inbound internal messages";
block_limit_class_ = std::max(block_limit_class_, block_limit_status_->classify());
stats_.limits_log += PSTRING() << "INBOUND_INT_MESSAGES: "
<< block_full_comment(*block_limit_status_, block::ParamLimits::cl_normal) << "\n";
break;
Expand Down Expand Up @@ -3659,6 +3663,7 @@ bool Collator::process_inbound_external_messages() {
}
if (r > 0) {
full = !block_limit_status_->fits(block::ParamLimits::cl_soft);
block_limit_class_ = std::max(block_limit_class_, block_limit_status_->classify());
}
auto it = ext_msg_map.find(hash);
CHECK(it != ext_msg_map.end());
Expand Down Expand Up @@ -3761,6 +3766,7 @@ bool Collator::process_dispatch_queue() {
block_full_ = !block_limit_status_->fits(block::ParamLimits::cl_normal);
if (block_full_) {
LOG(INFO) << "BLOCK FULL, stop processing dispatch queue";
block_limit_class_ = std::max(block_limit_class_, block_limit_status_->classify());
stats_.limits_log += PSTRING() << "DISPATCH_QUEUE_STAGE_" << iter << ": "
<< block_full_comment(*block_limit_status_, block::ParamLimits::cl_normal)
<< "\n";
Expand Down Expand Up @@ -4787,11 +4793,11 @@ bool Collator::check_block_overload() {
LOG(INFO) << "block load statistics: gas=" << block_limit_status_->gas_used
<< " lt_delta=" << block_limit_status_->cur_lt - block_limit_status_->limits.start_lt
<< " size_estimate=" << block_size_estimate_;
auto cl = block_limit_status_->classify();
if (cl >= block::ParamLimits::cl_soft || dispatch_queue_total_limit_reached_) {
block_limit_class_ = std::max(block_limit_class_, block_limit_status_->classify());
if (block_limit_class_ >= block::ParamLimits::cl_soft || dispatch_queue_total_limit_reached_) {
std::string message = "block is overloaded ";
if (cl >= block::ParamLimits::cl_soft) {
message += PSTRING() << "(category " << cl << ")";
if (block_limit_class_ >= block::ParamLimits::cl_soft) {
message += PSTRING() << "(category " << block_limit_class_ << ")";
} else {
message += "(long dispatch queue processing)";
}
Expand All @@ -4802,7 +4808,7 @@ bool Collator::check_block_overload() {
overload_history_ |= 1;
LOG(INFO) << message;
}
} else if (cl <= block::ParamLimits::cl_underload) {
} else if (block_limit_class_ <= block::ParamLimits::cl_underload) {
if (out_msg_queue_size_ > MERGE_MAX_QUEUE_SIZE) {
LOG(INFO)
<< "block is underloaded, but don't set underload history because out_msg_queue size is too big to merge ("
Expand Down

0 comments on commit 90819bf

Please sign in to comment.