Skip to content

Commit

Permalink
Account for unprocessed messages in estimate_block_size; check consen…
Browse files Browse the repository at this point in the history
…sus_config limits in collator (#692)

Co-authored-by: SpyCheese <[email protected]>
  • Loading branch information
EmelyanenkoK and SpyCheese authored May 4, 2023
1 parent a78adf3 commit 1696ebf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crypto/block/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ td::uint64 BlockLimitStatus::estimate_block_size(const vm::NewCellStorageStat::S
sum += *extra;
}
return 2000 + (sum.bits >> 3) + sum.cells * 12 + sum.internal_refs * 3 + sum.external_refs * 40 + accounts * 200 +
transactions * 200 + (extra ? 200 : 0);
transactions * 200 + (extra ? 200 : 0) + extra_out_msgs * 300;
}

int BlockLimitStatus::classify() const {
Expand Down
3 changes: 2 additions & 1 deletion crypto/block/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ struct BlockLimitStatus {
ton::LogicalTime cur_lt;
td::uint64 gas_used{};
vm::NewCellStorageStat st_stat;
unsigned accounts{}, transactions{};
unsigned accounts{}, transactions{}, extra_out_msgs{};
BlockLimitStatus(const BlockLimits& limits_, ton::LogicalTime lt = 0)
: limits(limits_), cur_lt(std::max(limits_.start_lt, lt)) {
}
Expand All @@ -270,6 +270,7 @@ struct BlockLimitStatus {
st_stat.set_zero();
transactions = accounts = 0;
gas_used = 0;
extra_out_msgs = 0;
}
td::uint64 estimate_block_size(const vm::NewCellStorageStat::Stat* extra = nullptr) const;
int classify() const;
Expand Down
14 changes: 14 additions & 0 deletions validator/impl/collator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2961,6 +2961,7 @@ bool Collator::process_new_messages(bool enqueue_only) {
while (!new_msgs.empty()) {
block::NewOutMsg msg = new_msgs.top();
new_msgs.pop();
block_limit_status_->extra_out_msgs--;
if (block_full_ && !enqueue_only) {
LOG(INFO) << "BLOCK FULL, enqueue all remaining new messages";
enqueue_only = true;
Expand All @@ -2982,6 +2983,7 @@ void Collator::register_new_msg(block::NewOutMsg new_msg) {
min_new_msg_lt = new_msg.lt;
}
new_msgs.push(std::move(new_msg));
block_limit_status_->extra_out_msgs++;
}

void Collator::register_new_msgs(block::transaction::Transaction& trans) {
Expand Down Expand Up @@ -3972,6 +3974,18 @@ bool Collator::create_block_candidate() {
ton::BlockIdExt{ton::BlockId{shard_, new_block_seqno}, new_block->get_hash().bits(),
block::compute_file_hash(blk_slice.as_slice())},
block::compute_file_hash(cdata_slice.as_slice()), blk_slice.clone(), cdata_slice.clone());
// 3.1 check block and collated data size
auto consensus_config = config_->get_consensus_config();
if (block_candidate->data.size() > consensus_config.max_block_size) {
return fatal_error(PSTRING() << "block size (" << block_candidate->data.size()
<< ") exceeds the limit in consensus config (" << consensus_config.max_block_size
<< ")");
}
if (block_candidate->collated_data.size() > consensus_config.max_collated_data_size) {
return fatal_error(PSTRING() << "collated data size (" << block_candidate->collated_data.size()
<< ") exceeds the limit in consensus config ("
<< consensus_config.max_collated_data_size << ")");
}
// 4. save block candidate
LOG(INFO) << "saving new BlockCandidate";
td::actor::send_closure_later(manager, &ValidatorManager::set_block_candidate, block_candidate->id,
Expand Down

0 comments on commit 1696ebf

Please sign in to comment.