1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Check limits in validate-query, check timeout in collator (#469)

This commit is contained in:
SpyCheese 2022-10-06 21:31:41 +03:00 committed by GitHub
parent caffdbb5ba
commit 580884033b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 5 deletions

View file

@ -2265,9 +2265,15 @@ bool Transaction::would_fit(unsigned cls, const block::BlockLimitStatus& blimst)
return blimst.would_fit(cls, end_lt, gas_used(), &extra); return blimst.would_fit(cls, end_lt, gas_used(), &extra);
} }
bool Transaction::update_limits(block::BlockLimitStatus& blimst) const { bool Transaction::update_limits(block::BlockLimitStatus& blimst, bool with_size) const {
return blimst.update_lt(end_lt) && blimst.update_gas(gas_used()) && blimst.add_proof(new_total_state) && if (!(blimst.update_lt(end_lt) && blimst.update_gas(gas_used()))) {
blimst.add_cell(root) && blimst.add_transaction() && blimst.add_account(is_first); return false;
}
if (with_size) {
return blimst.add_proof(new_total_state) && blimst.add_cell(root) && blimst.add_transaction() &&
blimst.add_account(is_first);
}
return true;
} }
/* /*

View file

@ -359,7 +359,7 @@ struct Transaction {
const vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const; const vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const;
bool update_block_storage_profile(vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const; bool update_block_storage_profile(vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const;
bool would_fit(unsigned cls, const block::BlockLimitStatus& blk_lim_st) const; bool would_fit(unsigned cls, const block::BlockLimitStatus& blk_lim_st) const;
bool update_limits(block::BlockLimitStatus& blk_lim_st) const; bool update_limits(block::BlockLimitStatus& blk_lim_st, bool with_size = true) const;
Ref<vm::Cell> commit(Account& _account); // _account should point to the same account Ref<vm::Cell> commit(Account& _account); // _account should point to the same account
LtCellRef extract_out_msg(unsigned i); LtCellRef extract_out_msg(unsigned i);

View file

@ -73,6 +73,7 @@ class Collator final : public td::actor::Actor {
Ref<ValidatorSet> validator_set_; Ref<ValidatorSet> validator_set_;
td::actor::ActorId<ValidatorManager> manager; td::actor::ActorId<ValidatorManager> manager;
td::Timestamp timeout; td::Timestamp timeout;
td::Timestamp soft_timeout_, medium_timeout_;
td::Promise<BlockCandidate> main_promise; td::Promise<BlockCandidate> main_promise;
ton::BlockSeqno last_block_seqno{0}; ton::BlockSeqno last_block_seqno{0};
ton::BlockSeqno prev_mc_block_seqno{0}; ton::BlockSeqno prev_mc_block_seqno{0};

View file

@ -67,6 +67,8 @@ Collator::Collator(ShardIdFull shard, bool is_hardfork, UnixTime min_ts, BlockId
, validator_set_(std::move(validator_set)) , validator_set_(std::move(validator_set))
, manager(manager) , manager(manager)
, timeout(timeout) , timeout(timeout)
, soft_timeout_(td::Timestamp::at(timeout.at() - 3.0))
, medium_timeout_(td::Timestamp::at(timeout.at() - 1.5))
, main_promise(std::move(promise)) , main_promise(std::move(promise))
, perf_timer_("collate", 0.1, [manager](double duration) { , perf_timer_("collate", 0.1, [manager](double duration) {
send_closure(manager, &ValidatorManager::add_perf_timer_stat, "collate", duration); send_closure(manager, &ValidatorManager::add_perf_timer_stat, "collate", duration);
@ -2503,6 +2505,11 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R
block_full_ = true; block_full_ = true;
return 3; return 3;
} }
if (soft_timeout_.is_in_past(td::Timestamp::now())) {
LOG(WARNING) << "soft timeout reached, stop processing new messages";
block_full_ = true;
return 3;
}
return 1; return 1;
} }
@ -2767,6 +2774,11 @@ bool Collator::process_inbound_internal_messages() {
LOG(INFO) << "BLOCK FULL, stop processing inbound internal messages"; LOG(INFO) << "BLOCK FULL, stop processing inbound internal messages";
break; break;
} }
if (soft_timeout_.is_in_past(td::Timestamp::now())) {
block_full_ = true;
LOG(WARNING) << "soft timeout reached, stop processing inbound internal messages";
break;
}
auto kv = nb_out_msgs_->extract_cur(); auto kv = nb_out_msgs_->extract_cur();
CHECK(kv && kv->msg.not_null()); CHECK(kv && kv->msg.not_null());
LOG(DEBUG) << "processing inbound message with (lt,hash)=(" << kv->lt << "," << kv->key.to_hex() LOG(DEBUG) << "processing inbound message with (lt,hash)=(" << kv->lt << "," << kv->key.to_hex()
@ -2800,6 +2812,10 @@ bool Collator::process_inbound_external_messages() {
LOG(INFO) << "BLOCK FULL, stop processing external messages"; LOG(INFO) << "BLOCK FULL, stop processing external messages";
break; break;
} }
if (medium_timeout_.is_in_past(td::Timestamp::now())) {
LOG(WARNING) << "medium timeout reached, stop processing inbound external messages";
break;
}
auto ext_msg = ext_msg_pair.first; auto ext_msg = ext_msg_pair.first;
ton::Bits256 hash{ext_msg->get_hash().bits()}; ton::Bits256 hash{ext_msg->get_hash().bits()};
int r = process_external_message(std::move(ext_msg)); int r = process_external_message(std::move(ext_msg));

View file

@ -734,6 +734,8 @@ bool ValidateQuery::try_unpack_mc_state() {
return fatal_error(limits.move_as_error()); return fatal_error(limits.move_as_error());
} }
block_limits_ = limits.move_as_ok(); block_limits_ = limits.move_as_ok();
block_limits_->start_lt = start_lt_;
block_limit_status_ = std::make_unique<block::BlockLimitStatus>(*block_limits_);
if (!fetch_config_params()) { if (!fetch_config_params()) {
return false; return false;
} }
@ -4335,6 +4337,13 @@ bool ValidateQuery::check_one_transaction(block::Account& account, ton::LogicalT
int trans_type = block::Transaction::tr_none; int trans_type = block::Transaction::tr_none;
switch (tag) { switch (tag) {
case block::gen::TransactionDescr::trans_ord: { case block::gen::TransactionDescr::trans_ord: {
if (!block_limit_status_->fits(block::ParamLimits::cl_medium)) {
return reject_query(PSTRING() << "cannod add ordinary transaction because hard block limits are exceeded: "
<< "gas_used=" << block_limit_status_->gas_used
<< "(limit=" << block_limits_->gas.hard() << "), "
<< "lt_delta=" << block_limit_status_->cur_lt - block_limits_->start_lt
<< "(limit=" << block_limits_->lt_delta.hard() << ")");
}
trans_type = block::Transaction::tr_ord; trans_type = block::Transaction::tr_ord;
if (in_msg_root.is_null()) { if (in_msg_root.is_null()) {
return reject_query(PSTRING() << "ordinary transaction " << lt << " of account " << addr.to_hex() return reject_query(PSTRING() << "ordinary transaction " << lt << " of account " << addr.to_hex()
@ -4480,7 +4489,7 @@ bool ValidateQuery::check_one_transaction(block::Account& account, ton::LogicalT
return reject_query(PSTRING() << "cannot re-create the serialization of transaction " << lt return reject_query(PSTRING() << "cannot re-create the serialization of transaction " << lt
<< " for smart contract " << addr.to_hex()); << " for smart contract " << addr.to_hex());
} }
if (block_limit_status_ && !trs->update_limits(*block_limit_status_)) { if (!trs->update_limits(*block_limit_status_, false)) {
return fatal_error(PSTRING() << "cannot update block limit status to include transaction " << lt << " of account " return fatal_error(PSTRING() << "cannot update block limit status to include transaction " << lt << " of account "
<< addr.to_hex()); << addr.to_hex());
} }