From 1cd34e3a2830b0b394fed3a565127c4240a58269 Mon Sep 17 00:00:00 2001 From: SpyCheese Date: Fri, 24 May 2024 11:59:09 +0300 Subject: [PATCH] Enable new features by capabilities --- ton/ton-types.h | 4 +++- validator/impl/collator-impl.h | 8 +++++--- validator/impl/collator.cpp | 10 +++++++--- validator/impl/validate-query.cpp | 13 +++++++++---- validator/impl/validate-query.hpp | 8 +++++--- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/ton/ton-types.h b/ton/ton-types.h index 107fc4509..915682655 100644 --- a/ton/ton-types.h +++ b/ton/ton-types.h @@ -58,7 +58,9 @@ enum GlobalCapabilities { capReportVersion = 8, capSplitMergeTransactions = 16, capShortDequeue = 32, - capStoreOutMsgQueueSize = 64 + capStoreOutMsgQueueSize = 64, + capMsgMetadata = 128, + capDeferMessages = 256 }; inline int shard_pfx_len(ShardId shard) { diff --git a/validator/impl/collator-impl.h b/validator/impl/collator-impl.h index 80c40894a..7877f1a58 100644 --- a/validator/impl/collator-impl.h +++ b/validator/impl/collator-impl.h @@ -45,7 +45,7 @@ class Collator final : public td::actor::Actor { } static constexpr long long supported_capabilities() { return ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion | ton::capShortDequeue | - ton::capStoreOutMsgQueueSize; + ton::capStoreOutMsgQueueSize | ton::capMsgMetadata | ton::capDeferMessages; } using LtCellRef = block::LtCellRef; using NewOutMsg = block::NewOutMsg; @@ -209,10 +209,12 @@ class Collator final : public td::actor::Actor { std::map sender_generated_messages_count_; unsigned dispatch_queue_ops_{0}; std::map last_enqueued_deferred_lt_; - bool msg_metadata_enabled_ = true; // TODO: enable by config - bool store_out_msg_queue_size_ = true; bool have_unprocessed_account_dispatch_queue_ = true; + bool msg_metadata_enabled_ = false; + bool deferring_messages_enabled_ = false; + bool store_out_msg_queue_size_ = false; + td::PerfWarningTimer perf_timer_; // block::Account* lookup_account(td::ConstBitPtr addr) const; diff --git a/validator/impl/collator.cpp b/validator/impl/collator.cpp index 0ff4d0df9..5b47ccf87 100644 --- a/validator/impl/collator.cpp +++ b/validator/impl/collator.cpp @@ -50,6 +50,7 @@ static const td::uint32 SPLIT_MAX_QUEUE_SIZE = 100000; static const td::uint32 MERGE_MAX_QUEUE_SIZE = 2047; static const td::uint32 SKIP_EXTERNALS_QUEUE_SIZE = 8000; static const int HIGH_PRIORITY_EXTERNAL = 10; // don't skip high priority externals when queue is big +static const int DEFER_MESSAGES_AFTER = 10; // 10'th and later messages from address will be deferred #define DBG(__n) dbg(__n)&& #define DSTART int __dcnt = 0; @@ -695,6 +696,8 @@ bool Collator::unpack_last_mc_state() { report_version_ = config_->has_capability(ton::capReportVersion); short_dequeue_records_ = config_->has_capability(ton::capShortDequeue); store_out_msg_queue_size_ = config_->has_capability(ton::capStoreOutMsgQueueSize); + msg_metadata_enabled_ = config_->has_capability(ton::capMsgMetadata); + deferring_messages_enabled_ = config_->has_capability(ton::capDeferMessages); shard_conf_ = std::make_unique(*config_); prev_key_block_exists_ = config_->get_last_key_block(prev_key_block_, prev_key_block_lt_); if (prev_key_block_exists_) { @@ -3047,8 +3050,8 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R CHECK(src_wc == workchain()); bool is_special_account = is_masterchain() && config_->is_special_smartcontract(src_addr); bool defer = false; - if (!is_special && !is_special_account && msg.msg_idx != 0) { - if (++sender_generated_messages_count_[src_addr] >= 10) { + if (deferring_messages_enabled_ && !is_special && !is_special_account && msg.msg_idx != 0) { + if (++sender_generated_messages_count_[src_addr] >= DEFER_MESSAGES_AFTER) { defer = true; } } @@ -3609,7 +3612,8 @@ bool Collator::process_dispatch_queue() { if (account_dispatch_queue.is_null()) { return fatal_error("invalid dispatch queue in shard state"); } - if (iter == 1 && sender_generated_messages_count_[src_addr] >= 10) { + if (iter == 1 && sender_generated_messages_count_[src_addr] >= DEFER_MESSAGES_AFTER && + deferring_messages_enabled_) { cur_dispatch_queue.lookup_delete(src_addr); continue; } diff --git a/validator/impl/validate-query.cpp b/validator/impl/validate-query.cpp index a27fd1fad..39ee8c33e 100644 --- a/validator/impl/validate-query.cpp +++ b/validator/impl/validate-query.cpp @@ -896,6 +896,8 @@ bool ValidateQuery::try_unpack_mc_state() { return fatal_error("masterchain configuration does not admit creating block "s + id_.to_str()); } store_out_msg_queue_size_ = config_->has_capability(ton::capStoreOutMsgQueueSize); + msg_metadata_enabled_ = config_->has_capability(ton::capMsgMetadata); + deferring_messages_enabled_ = config_->has_capability(ton::capDeferMessages); } catch (vm::VmError& err) { return fatal_error(-666, err.get_msg()); } catch (vm::VmVirtError& err) { @@ -5253,11 +5255,14 @@ bool ValidateQuery::check_one_transaction(block::Account& account, ton::LogicalT if (is_deferred) { LOG(INFO) << "message from account " << workchain() << ":" << ss_addr.to_hex() << " with lt " << message_lt << " was deferred"; + if (!deferring_messages_enabled_ && !account_expected_defer_all_messages_.count(ss_addr)) { + return reject_query(PSTRING() << "outbound message #" << i + 1 << " on account " << workchain() << ":" + << ss_addr.to_hex() << " is deferred, but deferring messages is disabled"); + } if (i == 0 && !account_expected_defer_all_messages_.count(ss_addr)) { - return reject_query( - PSTRING() << "outbound message #1 on account " << workchain() << ":" << ss_addr.to_hex() - << " must not be deferred (the first message cin transaction annot be deferred unless some " - "prevoius messages are deferred)"); + return reject_query(PSTRING() << "outbound message #1 on account " << workchain() << ":" << ss_addr.to_hex() + << " must not be deferred (the first message cannot be deferred unless some " + "prevoius messages are deferred)"); } account_expected_defer_all_messages_.insert(ss_addr); } diff --git a/validator/impl/validate-query.hpp b/validator/impl/validate-query.hpp index 172b053a2..4339fcce0 100644 --- a/validator/impl/validate-query.hpp +++ b/validator/impl/validate-query.hpp @@ -113,7 +113,7 @@ class ValidateQuery : public td::actor::Actor { } static constexpr long long supported_capabilities() { return ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion | ton::capShortDequeue | - ton::capStoreOutMsgQueueSize; + ton::capStoreOutMsgQueueSize | ton::capMsgMetadata | ton::capDeferMessages; } public: @@ -233,10 +233,12 @@ class ValidateQuery : public td::actor::Actor { std::map, Ref> removed_dispatch_queue_messages_; std::map, Ref> new_dispatch_queue_messages_; - bool msg_metadata_enabled_ = true; std::set account_expected_defer_all_messages_; td::uint64 old_out_msg_queue_size_ = 0, new_out_msg_queue_size_ = 0; - bool store_out_msg_queue_size_ = true; + + bool msg_metadata_enabled_ = false; + bool deferring_messages_enabled_ = false; + bool store_out_msg_queue_size_ = false; bool have_unprocessed_account_dispatch_queue_ = false;