Skip to content

Commit

Permalink
Enable new features by capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
SpyCheese committed May 24, 2024
1 parent 8054d63 commit 560fb2c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
4 changes: 3 additions & 1 deletion ton/ton-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions validator/impl/collator-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,10 +209,12 @@ class Collator final : public td::actor::Actor {
std::map<StdSmcAddress, td::uint32> sender_generated_messages_count_;
unsigned dispatch_queue_ops_{0};
std::map<StdSmcAddress, LogicalTime> 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;
Expand Down
9 changes: 6 additions & 3 deletions validator/impl/collator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<block::ShardConfig>(*config_);
prev_key_block_exists_ = config_->get_last_key_block(prev_key_block_, prev_key_block_lt_);
if (prev_key_block_exists_) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -3609,7 +3612,7 @@ 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) {
cur_dispatch_queue.lookup_delete(src_addr);
continue;
}
Expand Down
13 changes: 9 additions & 4 deletions validator/impl/validate-query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions validator/impl/validate-query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -233,10 +233,12 @@ class ValidateQuery : public td::actor::Actor {

std::map<std::pair<StdSmcAddress, td::uint64>, Ref<vm::Cell>> removed_dispatch_queue_messages_;
std::map<std::pair<StdSmcAddress, td::uint64>, Ref<vm::Cell>> new_dispatch_queue_messages_;
bool msg_metadata_enabled_ = true;
std::set<StdSmcAddress> 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;

Expand Down

0 comments on commit 560fb2c

Please sign in to comment.