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

Merge message dispatch queue (#1030)

* Deferred messages and msg metadata

* Store out msg queue size in state

* Add checks for queue processing

1. Collator must process at least one message from AccountDispatchQueue (unless block is full)
2. The first message from a transaction is not counted, it cannot be deferred (unless AccountDispatchQueue is not empty)

* Return msg metadata from LS in listBlockTransactions[Ext]

* Enable new features by capabilities

* Changes in deferred messages

* Process deferred messages via new_msgs in collator
* Rework setting deferred_lt, bring back check_message_processing_order, check order of deferred_lt in validator

* Use have_unprocessed_account_dispatch_queue_ in collator

* Fix setting transaction lt for deferred messages

* Fix lite-client compilation error

* Changes in process_dispatch_queue, rename deferred_lt -> emitted_lt

* Fix compilation error

* Use uint64 for msg queue size

* Add liteServer.getBlockOutMsgQueueSize

* Fix compilation error

* Fix typos in comments

---------

Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
EmelyanenkoK 2024-06-27 16:12:23 +03:00 committed by GitHub
parent 38fc1d5456
commit 0daee1d887
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 1889 additions and 318 deletions

View file

@ -44,7 +44,8 @@ class Collator final : public td::actor::Actor {
return SUPPORTED_VERSION;
}
static constexpr long long supported_capabilities() {
return ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion | ton::capShortDequeue;
return ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion | ton::capShortDequeue |
ton::capStoreOutMsgQueueSize | ton::capMsgMetadata | ton::capDeferMessages;
}
using LtCellRef = block::LtCellRef;
using NewOutMsg = block::NewOutMsg;
@ -192,7 +193,9 @@ class Collator final : public td::actor::Actor {
std::priority_queue<NewOutMsg, std::vector<NewOutMsg>, std::greater<NewOutMsg>> new_msgs;
std::pair<ton::LogicalTime, ton::Bits256> last_proc_int_msg_, first_unproc_int_msg_;
std::unique_ptr<vm::AugmentedDictionary> in_msg_dict, out_msg_dict, out_msg_queue_, sibling_out_msg_queue_;
td::uint32 out_msg_queue_size_ = 0;
std::map<StdSmcAddress, size_t> unprocessed_deferred_messages_; // number of messages from dispatch queue in new_msgs
td::uint64 out_msg_queue_size_ = 0;
bool have_out_msg_queue_size_in_state_ = false;
std::unique_ptr<vm::Dictionary> ihr_pending;
std::shared_ptr<block::MsgProcessedUptoCollection> processed_upto_, sibling_processed_upto_;
std::unique_ptr<vm::Dictionary> block_create_stats_;
@ -203,6 +206,16 @@ class Collator final : public td::actor::Actor {
std::vector<Ref<vm::Cell>> collated_roots_;
std::unique_ptr<ton::BlockCandidate> block_candidate;
std::unique_ptr<vm::AugmentedDictionary> dispatch_queue_;
std::map<StdSmcAddress, td::uint32> sender_generated_messages_count_;
unsigned dispatch_queue_ops_{0};
std::map<StdSmcAddress, LogicalTime> last_dispatch_queue_emitted_lt_;
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;
@ -231,7 +244,7 @@ class Collator final : public td::actor::Actor {
bool fix_one_processed_upto(block::MsgProcessedUpto& proc, const ton::ShardIdFull& owner);
bool fix_processed_upto(block::MsgProcessedUptoCollection& upto);
void got_neighbor_out_queue(int i, td::Result<Ref<MessageQueue>> res);
void got_out_queue_size(size_t i, td::Result<td::uint32> res);
void got_out_queue_size(size_t i, td::Result<td::uint64> res);
bool adjust_shard_config();
bool store_shard_fees(ShardIdFull shard, const block::CurrencyCollection& fees,
const block::CurrencyCollection& created);
@ -249,7 +262,8 @@ class Collator final : public td::actor::Actor {
Ref<vm::Cell>& in_msg);
bool create_ticktock_transactions(int mask);
bool create_ticktock_transaction(const ton::StdSmcAddress& smc_addr, ton::LogicalTime req_start_lt, int mask);
Ref<vm::Cell> create_ordinary_transaction(Ref<vm::Cell> msg_root, bool is_special_tx = false);
Ref<vm::Cell> create_ordinary_transaction(Ref<vm::Cell> msg_root, td::optional<block::MsgMetadata> msg_metadata,
LogicalTime after_lt, bool is_special_tx = false);
bool check_cur_validator_set();
bool unpack_last_mc_state();
bool unpack_last_state();
@ -278,7 +292,7 @@ class Collator final : public td::actor::Actor {
int priority);
// td::Result<bool> register_external_message(td::Slice ext_msg_boc);
void register_new_msg(block::NewOutMsg msg);
void register_new_msgs(block::transaction::Transaction& trans);
void register_new_msgs(block::transaction::Transaction& trans, td::optional<block::MsgMetadata> msg_metadata);
bool process_new_messages(bool enqueue_only = false);
int process_one_new_message(block::NewOutMsg msg, bool enqueue_only = false, Ref<vm::Cell>* is_special = nullptr);
bool process_inbound_internal_messages();
@ -286,10 +300,15 @@ class Collator final : public td::actor::Actor {
const block::McShardDescr& src_nb);
bool process_inbound_external_messages();
int process_external_message(Ref<vm::Cell> msg);
bool enqueue_message(block::NewOutMsg msg, td::RefInt256 fwd_fees_remaining, ton::LogicalTime enqueued_lt);
bool process_dispatch_queue();
bool process_deferred_message(Ref<vm::CellSlice> enq_msg, StdSmcAddress src_addr, LogicalTime lt,
td::optional<block::MsgMetadata>& msg_metadata);
bool enqueue_message(block::NewOutMsg msg, td::RefInt256 fwd_fees_remaining, StdSmcAddress src_addr,
bool defer = false);
bool enqueue_transit_message(Ref<vm::Cell> msg, Ref<vm::Cell> old_msg_env, ton::AccountIdPrefixFull prev_prefix,
ton::AccountIdPrefixFull cur_prefix, ton::AccountIdPrefixFull dest_prefix,
td::RefInt256 fwd_fee_remaining);
td::RefInt256 fwd_fee_remaining, td::optional<block::MsgMetadata> msg_metadata,
td::optional<LogicalTime> emitted_lt = {});
bool delete_out_msg_queue_msg(td::ConstBitPtr key);
bool insert_in_msg(Ref<vm::Cell> in_msg);
bool insert_out_msg(Ref<vm::Cell> out_msg);

View file

@ -1,7 +1,7 @@
/*
This file is part of TON Blockchain Library.
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
@ -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;
@ -694,6 +695,9 @@ bool Collator::unpack_last_mc_state() {
create_stats_enabled_ = config_->create_stats_enabled();
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_) {
@ -794,19 +798,20 @@ bool Collator::request_neighbor_msg_queues() {
}
/**
* Requests the size of the outbound message queue from the previous state(s).
* Requests the size of the outbound message queue from the previous state(s) if needed.
*
* @returns True if the request was successful, false otherwise.
*/
bool Collator::request_out_msg_queue_size() {
if (after_split_) {
// If block is after split, the size is calculated during split (see Collator::split_last_state)
if (have_out_msg_queue_size_in_state_) {
// if after_split then have_out_msg_queue_size_in_state_ is always true, since the size is calculated during split
return true;
}
out_msg_queue_size_ = 0;
for (size_t i = 0; i < prev_blocks.size(); ++i) {
++pending;
send_closure_later(manager, &ValidatorManager::get_out_msg_queue_size, prev_blocks[i],
[self = get_self(), i](td::Result<td::uint32> res) {
[self = get_self(), i](td::Result<td::uint64> res) {
td::actor::send_closure(std::move(self), &Collator::got_out_queue_size, i, std::move(res));
});
}
@ -885,14 +890,14 @@ void Collator::got_neighbor_out_queue(int i, td::Result<Ref<MessageQueue>> res)
* @param i The index of the previous block (0 or 1).
* @param res The result object containing the size of the queue.
*/
void Collator::got_out_queue_size(size_t i, td::Result<td::uint32> res) {
void Collator::got_out_queue_size(size_t i, td::Result<td::uint64> res) {
--pending;
if (res.is_error()) {
fatal_error(
res.move_as_error_prefix(PSTRING() << "failed to get message queue size from prev block #" << i << ": "));
return;
}
td::uint32 size = res.move_as_ok();
td::uint64 size = res.move_as_ok();
LOG(WARNING) << "got outbound queue size from prev block #" << i << ": " << size;
out_msg_queue_size_ += size;
check_pending();
@ -1016,7 +1021,7 @@ bool Collator::split_last_state(block::ShardState& ss) {
return fatal_error(res2.move_as_error());
}
sibling_processed_upto_ = res2.move_as_ok();
auto res3 = ss.split(shard_, &out_msg_queue_size_);
auto res3 = ss.split(shard_);
if (res3.is_error()) {
return fatal_error(std::move(res3));
}
@ -1052,7 +1057,12 @@ bool Collator::import_shard_state_data(block::ShardState& ss) {
out_msg_queue_ = std::move(ss.out_msg_queue_);
processed_upto_ = std::move(ss.processed_upto_);
ihr_pending = std::move(ss.ihr_pending_);
dispatch_queue_ = std::move(ss.dispatch_queue_);
block_create_stats_ = std::move(ss.block_create_stats_);
if (ss.out_msg_queue_size_) {
have_out_msg_queue_size_in_state_ = true;
out_msg_queue_size_ = ss.out_msg_queue_size_.value();
}
return true;
}
@ -2090,6 +2100,11 @@ bool Collator::do_collate() {
if (!init_value_create()) {
return fatal_error("cannot compute the value to be created / minted / recovered");
}
// 2-. take messages from dispatch queue
LOG(INFO) << "process dispatch queue";
if (!process_dispatch_queue()) {
return fatal_error("cannot process dispatch queue");
}
// 2. tick transactions
LOG(INFO) << "create tick transactions";
if (!create_ticktock_transactions(2)) {
@ -2597,7 +2612,7 @@ bool Collator::create_special_transaction(block::CurrencyCollection amount, Ref<
}
CHECK(block::gen::t_Message_Any.validate_ref(msg));
CHECK(block::tlb::t_Message.validate_ref(msg));
if (process_one_new_message(block::NewOutMsg{lt, msg, Ref<vm::Cell>{}}, false, &in_msg) != 1) {
if (process_one_new_message(block::NewOutMsg{lt, msg, Ref<vm::Cell>{}, 0}, false, &in_msg) != 1) {
return fatal_error("cannot generate special transaction for recovering "s + amount.to_str() + " to account " +
addr.to_hex());
}
@ -2639,13 +2654,18 @@ bool Collator::create_ticktock_transaction(const ton::StdSmcAddress& smc_addr, t
return true;
}
req_start_lt = std::max(req_start_lt, start_lt + 1);
auto it = last_dispatch_queue_emitted_lt_.find(acc->addr);
if (it != last_dispatch_queue_emitted_lt_.end()) {
req_start_lt = std::max(req_start_lt, it->second + 1);
}
if (acc->last_trans_end_lt_ >= start_lt && acc->transactions.empty()) {
return fatal_error(td::Status::Error(-666, PSTRING()
<< "last transaction time in the state of account " << workchain()
<< ":" << smc_addr.to_hex() << " is too large"));
}
std::unique_ptr<block::transaction::Transaction> trans = std::make_unique<block::transaction::Transaction>(
*acc, mask == 2 ? block::transaction::Transaction::tr_tick : block::transaction::Transaction::tr_tock, req_start_lt, now_);
*acc, mask == 2 ? block::transaction::Transaction::tr_tick : block::transaction::Transaction::tr_tock,
req_start_lt, now_);
if (!trans->prepare_storage_phase(storage_phase_cfg_, true)) {
return fatal_error(td::Status::Error(
-666, std::string{"cannot create storage phase of a new transaction for smart contract "} + smc_addr.to_hex()));
@ -2675,7 +2695,8 @@ bool Collator::create_ticktock_transaction(const ton::StdSmcAddress& smc_addr, t
td::Status::Error(-666, std::string{"cannot commit new transaction for smart contract "} + smc_addr.to_hex()));
}
update_max_lt(acc->last_trans_end_lt_);
register_new_msgs(*trans);
block::MsgMetadata new_msg_metadata{0, acc->workchain, acc->addr, trans->start_lt};
register_new_msgs(*trans, std::move(new_msg_metadata));
return true;
}
@ -2683,11 +2704,15 @@ bool Collator::create_ticktock_transaction(const ton::StdSmcAddress& smc_addr, t
* Creates an ordinary transaction using a given message.
*
* @param msg_root The root of the message to be processed serialized using Message TLB-scheme.
* @param msg_metadata Metadata of the inbound message.
* @param after_lt Transaction lt will be grater than after_lt. Used for deferred messages.
* @param is_special_tx True if creating a special transaction (mint/recover), false otherwise.
*
* @returns The root of the serialized transaction, or an empty reference if the transaction creation fails.
*/
Ref<vm::Cell> Collator::create_ordinary_transaction(Ref<vm::Cell> msg_root, bool is_special_tx) {
Ref<vm::Cell> Collator::create_ordinary_transaction(Ref<vm::Cell> msg_root,
td::optional<block::MsgMetadata> msg_metadata, LogicalTime after_lt,
bool is_special_tx) {
ton::StdSmcAddress addr;
auto cs = vm::load_cell_slice(msg_root);
bool external;
@ -2731,8 +2756,15 @@ Ref<vm::Cell> Collator::create_ordinary_transaction(Ref<vm::Cell> msg_root, bool
block::Account* acc = acc_res.move_as_ok();
assert(acc);
if (external) {
after_lt = std::max(after_lt, last_proc_int_msg_.first);
}
auto it = last_dispatch_queue_emitted_lt_.find(acc->addr);
if (it != last_dispatch_queue_emitted_lt_.end()) {
after_lt = std::max(after_lt, it->second);
}
auto res = impl_create_ordinary_transaction(msg_root, acc, now_, start_lt, &storage_phase_cfg_, &compute_phase_cfg_,
&action_phase_cfg_, external, last_proc_int_msg_.first);
&action_phase_cfg_, external, after_lt);
if (res.is_error()) {
auto error = res.move_as_error();
if (error.code() == -701) {
@ -2756,7 +2788,14 @@ Ref<vm::Cell> Collator::create_ordinary_transaction(Ref<vm::Cell> msg_root, bool
return {};
}
register_new_msgs(*trans);
td::optional<block::MsgMetadata> new_msg_metadata;
if (external || is_special_tx) {
new_msg_metadata = block::MsgMetadata{0, acc->workchain, acc->addr, trans->start_lt};
} else if (msg_metadata) {
new_msg_metadata = std::move(msg_metadata);
++new_msg_metadata.value().depth;
}
register_new_msgs(*trans, std::move(new_msg_metadata));
update_max_lt(acc->last_trans_end_lt_);
value_flow_.burned += trans->blackhole_burned;
return trans_root;
@ -2791,13 +2830,12 @@ td::Result<std::unique_ptr<block::transaction::Transaction>> Collator::impl_crea
<< ":" << acc->addr.to_hex() << " is too large");
}
auto trans_min_lt = lt;
if (external) {
// transactions processing external messages must have lt larger than all processed internal messages
trans_min_lt = std::max(trans_min_lt, after_lt);
}
// transactions processing external messages must have lt larger than all processed internal messages
// if account has deferred message processed in this block, the next transaction should have lt > emitted_lt
trans_min_lt = std::max(trans_min_lt, after_lt);
std::unique_ptr<block::transaction::Transaction> trans =
std::make_unique<block::transaction::Transaction>(*acc, block::transaction::Transaction::tr_ord, trans_min_lt + 1, utime, msg_root);
std::unique_ptr<block::transaction::Transaction> trans = std::make_unique<block::transaction::Transaction>(
*acc, block::transaction::Transaction::tr_ord, trans_min_lt + 1, utime, msg_root);
bool ihr_delivered = false; // FIXME
if (!trans->unpack_input_msg(ihr_delivered, action_phase_cfg)) {
if (external) {
@ -2948,7 +2986,7 @@ bool Collator::is_our_address(const ton::StdSmcAddress& addr) const {
}
/**
* Processes a message generated in this block.
* Processes a message generated in this block or a message from DispatchQueue.
*
* @param msg The new message to be processed.
* @param enqueue_only Flag indicating whether the message should only be enqueued.
@ -2961,6 +2999,7 @@ bool Collator::is_our_address(const ton::StdSmcAddress& addr) const {
* -1 - error occured.
*/
int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, Ref<vm::Cell>* is_special) {
bool from_dispatch_queue = msg.msg_env_from_dispatch_queue.not_null();
Ref<vm::CellSlice> src, dest;
bool enqueue, external;
auto cs = load_cell_slice(msg.msg);
@ -2972,7 +3011,7 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R
if (!tlb::unpack(cs, info)) {
return -1;
}
CHECK(info.created_lt == msg.lt && info.created_at == now_);
CHECK(info.created_lt == msg.lt && info.created_at == now_ && !from_dispatch_queue);
src = std::move(info.src);
enqueue = external = true;
break;
@ -2982,7 +3021,7 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R
if (!tlb::unpack(cs, info)) {
return -1;
}
CHECK(info.created_lt == msg.lt && info.created_at == now_);
CHECK(from_dispatch_queue || (info.created_lt == msg.lt && info.created_at == now_));
src = std::move(info.src);
dest = std::move(info.dest);
fwd_fees = block::tlb::t_Grams.as_integer(info.fwd_fee);
@ -2994,7 +3033,7 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R
default:
return -1;
}
CHECK(is_our_address(std::move(src)));
CHECK(is_our_address(src));
if (external) {
// 1. construct a msg_export_ext OutMsg
vm::CellBuilder cb;
@ -3006,9 +3045,44 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R
// (if ever a structure in the block for listing all external outbound messages appears, insert this message there as well)
return 0;
}
if (enqueue) {
auto lt = msg.lt;
bool ok = enqueue_message(std::move(msg), std::move(fwd_fees), lt);
WorkchainId src_wc;
StdSmcAddress src_addr;
CHECK(block::tlb::t_MsgAddressInt.extract_std_address(src, src_wc, src_addr));
CHECK(src_wc == workchain());
bool is_special_account = is_masterchain() && config_->is_special_smartcontract(src_addr);
bool defer = false;
if (!from_dispatch_queue) {
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;
}
}
if (dispatch_queue_->lookup(src_addr).not_null() || unprocessed_deferred_messages_.count(src_addr)) {
defer = true;
}
} else {
auto &x = unprocessed_deferred_messages_[src_addr];
CHECK(x > 0);
if (--x == 0) {
unprocessed_deferred_messages_.erase(src_addr);
}
}
if (enqueue || defer) {
bool ok;
if (from_dispatch_queue) {
auto msg_env = msg.msg_env_from_dispatch_queue;
block::tlb::MsgEnvelope::Record_std env;
CHECK(block::tlb::unpack_cell(msg_env, env));
auto src_prefix = block::tlb::MsgAddressInt::get_prefix(src);
auto dest_prefix = block::tlb::MsgAddressInt::get_prefix(dest);
CHECK(env.emitted_lt && env.emitted_lt.value() == msg.lt);
ok = enqueue_transit_message(std::move(msg.msg), std::move(msg_env), src_prefix, src_prefix, dest_prefix,
std::move(env.fwd_fee_remaining), std::move(env.metadata), msg.lt);
} else {
ok = enqueue_message(std::move(msg), std::move(fwd_fees), src_addr, defer);
}
return ok ? 0 : -1;
}
// process message by a transaction in this block:
@ -3019,26 +3093,36 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R
return -1;
}
// 1. create a Transaction processing this Message
auto trans_root = create_ordinary_transaction(msg.msg, is_special != nullptr);
auto trans_root = create_ordinary_transaction(msg.msg, msg.metadata, msg.lt, is_special != nullptr);
if (trans_root.is_null()) {
fatal_error("cannot create transaction for re-processing output message");
return -1;
}
// 2. create a MsgEnvelope enveloping this Message
vm::CellBuilder cb;
CHECK(cb.store_long_bool(0x46060, 20) // msg_envelope#4 cur_addr:.. next_addr:..
&& block::tlb::t_Grams.store_integer_ref(cb, fwd_fees) // fwd_fee_remaining:t_Grams
&& cb.store_ref_bool(msg.msg)); // msg:^(Message Any)
Ref<vm::Cell> msg_env = cb.finalize();
block::tlb::MsgEnvelope::Record_std msg_env_rec{0x60, 0x60, fwd_fees, msg.msg, {}, msg.metadata};
Ref<vm::Cell> msg_env;
CHECK(block::tlb::pack_cell(msg_env, msg_env_rec));
if (verbosity > 2) {
std::cerr << "new (processed outbound) message envelope: ";
block::gen::t_MsgEnvelope.print_ref(std::cerr, msg_env);
}
// 3. create InMsg, referring to this MsgEnvelope and this Transaction
CHECK(cb.store_long_bool(3, 3) // msg_import_imm$011
&& cb.store_ref_bool(msg_env) // in_msg:^MsgEnvelope
&& cb.store_ref_bool(trans_root) // transaction:^Transaction
&& block::tlb::t_Grams.store_integer_ref(cb, fwd_fees)); // fwd_fee:Grams
vm::CellBuilder cb;
if (from_dispatch_queue) {
auto msg_env = msg.msg_env_from_dispatch_queue;
block::tlb::MsgEnvelope::Record_std env;
CHECK(block::tlb::unpack_cell(msg_env, env));
CHECK(env.emitted_lt && env.emitted_lt.value() == msg.lt);
CHECK(cb.store_long_bool(0b00100, 5) // msg_import_deferred_fin$00100
&& cb.store_ref_bool(msg_env) // in_msg:^MsgEnvelope
&& cb.store_ref_bool(trans_root) // transaction:^Transaction
&& block::tlb::t_Grams.store_integer_ref(cb, env.fwd_fee_remaining)); // fwd_fee:Grams
} else {
CHECK(cb.store_long_bool(3, 3) // msg_import_imm$011
&& cb.store_ref_bool(msg_env) // in_msg:^MsgEnvelope
&& cb.store_ref_bool(trans_root) // transaction:^Transaction
&& block::tlb::t_Grams.store_integer_ref(cb, fwd_fees)); // fwd_fee:Grams
}
// 4. insert InMsg into InMsgDescr
Ref<vm::Cell> in_msg = cb.finalize();
if (!insert_in_msg(in_msg)) {
@ -3049,14 +3133,16 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R
*is_special = in_msg;
return 1;
}
// 5. create OutMsg, referring to this MsgEnvelope and InMsg
CHECK(cb.store_long_bool(2, 3) // msg_export_imm$010
&& cb.store_ref_bool(msg_env) // out_msg:^MsgEnvelope
&& cb.store_ref_bool(msg.trans) // transaction:^Transaction
&& cb.store_ref_bool(in_msg)); // reimport:^InMsg
// 6. insert OutMsg into OutMsgDescr
if (!insert_out_msg(cb.finalize())) {
return -1;
if (!from_dispatch_queue) {
// 5. create OutMsg, referring to this MsgEnvelope and InMsg
CHECK(cb.store_long_bool(2, 3) // msg_export_imm$010
&& cb.store_ref_bool(msg_env) // out_msg:^MsgEnvelope
&& cb.store_ref_bool(msg.trans) // transaction:^Transaction
&& cb.store_ref_bool(in_msg)); // reimport:^InMsg
// 6. insert OutMsg into OutMsgDescr
if (!insert_out_msg(cb.finalize())) {
return -1;
}
}
// 7. check whether the block is full now
if (!block_limit_status_->fits(block::ParamLimits::cl_normal)) {
@ -3081,41 +3167,61 @@ int Collator::process_one_new_message(block::NewOutMsg msg, bool enqueue_only, R
* @param cur_prefix The account ID prefix for the next hop.
* @param dest_prefix The prefix of the destination account ID.
* @param fwd_fee_remaining The remaining forward fee.
* @param msg_metadata Metadata of the message.
* @param emitted_lt If present - the message was taken from DispatchQueue, and msg_env will have this emitted_lt.
*
* @returns True if the transit message is successfully enqueued, false otherwise.
*/
bool Collator::enqueue_transit_message(Ref<vm::Cell> msg, Ref<vm::Cell> old_msg_env,
ton::AccountIdPrefixFull prev_prefix, ton::AccountIdPrefixFull cur_prefix,
ton::AccountIdPrefixFull dest_prefix, td::RefInt256 fwd_fee_remaining) {
LOG(DEBUG) << "enqueueing transit message " << msg->get_hash().bits().to_hex(256);
bool requeue = is_our_address(prev_prefix);
ton::AccountIdPrefixFull dest_prefix, td::RefInt256 fwd_fee_remaining,
td::optional<block::MsgMetadata> msg_metadata,
td::optional<LogicalTime> emitted_lt) {
bool from_dispatch_queue = (bool)emitted_lt;
if (from_dispatch_queue) {
LOG(DEBUG) << "enqueueing message from dispatch queue " << msg->get_hash().bits().to_hex(256)
<< ", emitted_lt=" << emitted_lt.value();
} else {
LOG(DEBUG) << "enqueueing transit message " << msg->get_hash().bits().to_hex(256);
}
bool requeue = !from_dispatch_queue && is_our_address(prev_prefix) && !from_dispatch_queue;
// 1. perform hypercube routing
auto route_info = block::perform_hypercube_routing(cur_prefix, dest_prefix, shard_);
if ((unsigned)route_info.first > 96 || (unsigned)route_info.second > 96) {
return fatal_error("cannot perform hypercube routing for a transit message");
}
// 2. compute our part of transit fees
td::RefInt256 transit_fee = action_phase_cfg_.fwd_std.get_next_part(fwd_fee_remaining);
td::RefInt256 transit_fee =
from_dispatch_queue ? td::zero_refint() : action_phase_cfg_.fwd_std.get_next_part(fwd_fee_remaining);
fwd_fee_remaining -= transit_fee;
CHECK(td::sgn(transit_fee) >= 0 && td::sgn(fwd_fee_remaining) >= 0);
// 3. create a new MsgEnvelope
vm::CellBuilder cb;
CHECK(cb.store_long_bool(4, 4) // msg_envelope#4 cur_addr:.. next_addr:..
&& cb.store_long_bool(route_info.first, 8) // cur_addr:IntermediateAddress
&& cb.store_long_bool(route_info.second, 8) // next_addr:IntermediateAddress
&& block::tlb::t_Grams.store_integer_ref(cb, fwd_fee_remaining) // fwd_fee_remaining:t_Grams
&& cb.store_ref_bool(msg)); // msg:^(Message Any)
Ref<vm::Cell> msg_env = cb.finalize();
block::tlb::MsgEnvelope::Record_std msg_env_rec{route_info.first, route_info.second, fwd_fee_remaining, msg,
emitted_lt, std::move(msg_metadata)};
Ref<vm::Cell> msg_env;
CHECK(block::tlb::t_MsgEnvelope.pack_cell(msg_env, msg_env_rec));
// 4. create InMsg
CHECK(cb.store_long_bool(5, 3) // msg_import_tr$101
&& cb.store_ref_bool(old_msg_env) // in_msg:^MsgEnvelope
&& cb.store_ref_bool(msg_env) // out_msg:^MsgEnvelope
&& block::tlb::t_Grams.store_integer_ref(cb, transit_fee)); // transit_fee:Grams
vm::CellBuilder cb;
if (from_dispatch_queue) {
CHECK(cb.store_long_bool(0b00101, 5) // msg_import_deferred_tr$00101
&& cb.store_ref_bool(old_msg_env) // in_msg:^MsgEnvelope
&& cb.store_ref_bool(msg_env)); // out_msg:^MsgEnvelope
} else {
CHECK(cb.store_long_bool(5, 3) // msg_import_tr$101
&& cb.store_ref_bool(old_msg_env) // in_msg:^MsgEnvelope
&& cb.store_ref_bool(msg_env) // out_msg:^MsgEnvelope
&& block::tlb::t_Grams.store_integer_ref(cb, transit_fee)); // transit_fee:Grams
}
Ref<vm::Cell> in_msg = cb.finalize();
// 5. create a new OutMsg
CHECK(cb.store_long_bool(requeue ? 7 : 3, 3) // msg_export_tr$011 or msg_export_tr_req$111
&& cb.store_ref_bool(msg_env) // out_msg:^MsgEnvelope
&& cb.store_ref_bool(in_msg)); // imported:^InMsg
// msg_export_tr$011 / msg_export_tr_req$111 / msg_export_deferred_tr$10101
if (from_dispatch_queue) {
CHECK(cb.store_long_bool(0b10101, 5));
} else {
CHECK(cb.store_long_bool(requeue ? 7 : 3, 3));
}
CHECK(cb.store_ref_bool(msg_env) // out_msg:^MsgEnvelope
&& cb.store_ref_bool(in_msg)); // imported:^InMsg
Ref<vm::Cell> out_msg = cb.finalize();
// 4.1. insert OutMsg into OutMsgDescr
if (verbosity > 2) {
@ -3134,8 +3240,8 @@ bool Collator::enqueue_transit_message(Ref<vm::Cell> msg, Ref<vm::Cell> old_msg_
return fatal_error("cannot insert a new InMsg into InMsgDescr");
}
// 5. create EnqueuedMsg
CHECK(cb.store_long_bool(start_lt) // _ enqueued_lt:uint64
&& cb.store_ref_bool(msg_env)); // out_msg:^MsgEnvelope = EnqueuedMsg;
CHECK(cb.store_long_bool(from_dispatch_queue ? emitted_lt.value() : start_lt) // _ enqueued_lt:uint64
&& cb.store_ref_bool(msg_env)); // out_msg:^MsgEnvelope = EnqueuedMsg;
// 6. insert EnqueuedMsg into OutMsgQueue
// NB: we use here cur_prefix instead of src_prefix; should we check that route_info.first >= next_addr.use_dest_bits of the old envelope?
auto next_hop = block::interpolate_addr(cur_prefix, dest_prefix, route_info.second);
@ -3237,9 +3343,14 @@ bool Collator::process_inbound_message(Ref<vm::CellSlice> enq_msg, ton::LogicalT
LOG(ERROR) << "cannot unpack CommonMsgInfo of an inbound internal message";
return false;
}
if (info.created_lt != lt) {
if (!env.emitted_lt && info.created_lt != lt) {
LOG(ERROR) << "inbound internal message has an augmentation value in source OutMsgQueue distinct from the one in "
"its contents";
"its contents (CommonMsgInfo)";
return false;
}
if (env.emitted_lt && env.emitted_lt.value() != lt) {
LOG(ERROR) << "inbound internal message has an augmentation value in source OutMsgQueue distinct from the one in "
"its contents (deferred_it in MsgEnvelope)";
return false;
}
if (!block::tlb::validate_message_libs(env.msg)) {
@ -3302,7 +3413,8 @@ bool Collator::process_inbound_message(Ref<vm::CellSlice> enq_msg, ton::LogicalT
bool our = ton::shard_contains(shard_, cur_prefix);
bool to_us = ton::shard_contains(shard_, dest_prefix);
block::EnqueuedMsgDescr enq_msg_descr{cur_prefix, next_prefix, info.created_lt, enqueued_lt,
block::EnqueuedMsgDescr enq_msg_descr{cur_prefix, next_prefix,
env.emitted_lt ? env.emitted_lt.value() : info.created_lt, enqueued_lt,
env.msg->get_hash().bits()};
if (processed_upto_->already_processed(enq_msg_descr)) {
LOG(DEBUG) << "inbound internal message with lt=" << enq_msg_descr.lt_ << " hash=" << enq_msg_descr.hash_.to_hex()
@ -3319,7 +3431,7 @@ bool Collator::process_inbound_message(Ref<vm::CellSlice> enq_msg, ton::LogicalT
// destination is outside our shard, relay transit message
// (very similar to enqueue_message())
if (!enqueue_transit_message(std::move(env.msg), std::move(msg_env), cur_prefix, next_prefix, dest_prefix,
std::move(env.fwd_fee_remaining))) {
std::move(env.fwd_fee_remaining), std::move(env.metadata))) {
return fatal_error("cannot enqueue transit internal message with key "s + key.to_hex(352));
}
return !our || delete_out_msg_queue_msg(key);
@ -3328,7 +3440,7 @@ bool Collator::process_inbound_message(Ref<vm::CellSlice> enq_msg, ton::LogicalT
// process the message by an ordinary transaction similarly to process_one_new_message()
//
// 8. create a Transaction processing this Message
auto trans_root = create_ordinary_transaction(env.msg);
auto trans_root = create_ordinary_transaction(env.msg, env.metadata, 0);
if (trans_root.is_null()) {
return fatal_error("cannot create transaction for processing inbound message");
}
@ -3368,6 +3480,9 @@ bool Collator::process_inbound_message(Ref<vm::CellSlice> enq_msg, ton::LogicalT
* @returns True if the processing was successful, false otherwise.
*/
bool Collator::process_inbound_internal_messages() {
if (have_unprocessed_account_dispatch_queue_) {
return true;
}
while (!block_full_ && !nb_out_msgs_->is_eof()) {
block_full_ = !block_limit_status_->fits(block::ParamLimits::cl_normal);
if (block_full_) {
@ -3476,7 +3591,7 @@ int Collator::process_external_message(Ref<vm::Cell> msg) {
}
// process message by a transaction in this block:
// 1. create a Transaction processing this Message
auto trans_root = create_ordinary_transaction(msg);
auto trans_root = create_ordinary_transaction(msg, /* metadata = */ {}, 0);
if (trans_root.is_null()) {
if (busy_) {
// transaction rejected by account
@ -3500,6 +3615,222 @@ int Collator::process_external_message(Ref<vm::Cell> msg) {
return 1;
}
/**
* Processes messages from dispatch queue
*
* Messages from dispatch queue are taken in three steps:
* 1. Take one message from each account (in the order of lt)
* 2. Take up to 10 per account (including from p.1), up to 20 per initiator, up to 150 in total
* 3. Take up to X messages per initiator, up to 150 in total. X depends on out msg queue size
*
* @returns True if the processing was successful, false otherwise.
*/
bool Collator::process_dispatch_queue() {
have_unprocessed_account_dispatch_queue_ = true;
size_t max_total_count[3] = {1 << 30, 150, 150};
size_t max_per_initiator[3] = {1 << 30, 20, 0};
if (out_msg_queue_size_ <= 256) {
max_per_initiator[2] = 10;
} else if (out_msg_queue_size_ <= 512) {
max_per_initiator[2] = 2;
} else if (out_msg_queue_size_ <= 2048) {
max_per_initiator[2] = 1;
}
for (int iter = 0; iter < 3; ++iter) {
if (max_per_initiator[iter] == 0) {
continue;
}
vm::AugmentedDictionary cur_dispatch_queue{dispatch_queue_->get_root(), 256, block::tlb::aug_DispatchQueue};
std::map<std::tuple<WorkchainId, StdSmcAddress, LogicalTime>, size_t> count_per_initiator;
size_t total_count = 0;
while (!cur_dispatch_queue.is_empty()) {
block_full_ = !block_limit_status_->fits(block::ParamLimits::cl_normal);
if (block_full_) {
LOG(INFO) << "BLOCK FULL, stop processing dispatch queue";
return true;
}
if (soft_timeout_.is_in_past(td::Timestamp::now())) {
block_full_ = true;
LOG(WARNING) << "soft timeout reached, stop processing dispatch queue";
return true;
}
StdSmcAddress src_addr;
auto account_dispatch_queue = block::get_dispatch_queue_min_lt_account(cur_dispatch_queue, src_addr);
if (account_dispatch_queue.is_null()) {
return fatal_error("invalid dispatch queue in shard state");
}
vm::Dictionary dict{64};
td::uint64 dict_size;
if (!block::unpack_account_dispatch_queue(account_dispatch_queue, dict, dict_size)) {
return fatal_error(PSTRING() << "invalid account dispatch queue for account " << src_addr.to_hex());
}
td::BitArray<64> key;
Ref<vm::CellSlice> enqueued_msg = dict.extract_minmax_key(key.bits(), 64, false, false);
LogicalTime lt = key.to_ulong();
td::optional<block::MsgMetadata> msg_metadata;
if (!process_deferred_message(std::move(enqueued_msg), src_addr, lt, msg_metadata)) {
return fatal_error(PSTRING() << "error processing internal message from dispatch queue: account="
<< src_addr.to_hex() << ", lt=" << lt);
}
// Remove message from DispatchQueue
bool ok;
if (iter == 0 || (iter == 1 && sender_generated_messages_count_[src_addr] >= DEFER_MESSAGES_AFTER)) {
ok = cur_dispatch_queue.lookup_delete(src_addr).not_null();
} else {
dict.lookup_delete(key);
--dict_size;
account_dispatch_queue = block::pack_account_dispatch_queue(dict, dict_size);
ok = account_dispatch_queue.not_null() ? cur_dispatch_queue.set(src_addr, account_dispatch_queue)
: cur_dispatch_queue.lookup_delete(src_addr).not_null();
}
if (!ok) {
return fatal_error(PSTRING() << "error processing internal message from dispatch queue: account="
<< src_addr.to_hex() << ", lt=" << lt);
}
if (msg_metadata) {
auto initiator = std::make_tuple(msg_metadata.value().initiator_wc, msg_metadata.value().initiator_addr,
msg_metadata.value().initiator_lt);
size_t initiator_count = ++count_per_initiator[initiator];
if (initiator_count >= max_per_initiator[iter]) {
cur_dispatch_queue.lookup_delete(src_addr);
}
}
++total_count;
if (total_count >= max_total_count[iter]) {
break;
}
}
if (iter == 0) {
have_unprocessed_account_dispatch_queue_ = false;
}
}
return true;
}
/**
* Processes an internal message from DispatchQueue.
* The message may create a transaction or be enqueued.
*
* Similar to Collator::process_inbound_message.
*
* @param enq_msg The internal message serialized using EnqueuedMsg TLB-scheme.
* @param src_addr 256-bit address of the sender.
* @param lt The logical time of the message.
* @param msg_metadata Reference to store msg_metadata
*
* @returns True if the message was processed successfully, false otherwise.
*/
bool Collator::process_deferred_message(Ref<vm::CellSlice> enq_msg, StdSmcAddress src_addr, LogicalTime lt,
td::optional<block::MsgMetadata>& msg_metadata) {
if (!block::remove_dispatch_queue_entry(*dispatch_queue_, src_addr, lt)) {
return fatal_error(PSTRING() << "failed to delete message from DispatchQueue: address=" << src_addr.to_hex()
<< ", lt=" << lt);
}
++dispatch_queue_ops_;
if (!(dispatch_queue_ops_ & 63)) {
if (!block_limit_status_->add_proof(dispatch_queue_->get_root_cell())) {
return false;
}
}
++sender_generated_messages_count_[src_addr];
LogicalTime enqueued_lt = 0;
if (enq_msg.is_null() || enq_msg->size_ext() != 0x10040 || (enqueued_lt = enq_msg->prefetch_ulong(64)) != lt) {
if (enq_msg.not_null()) {
block::gen::t_EnqueuedMsg.print(std::cerr, *enq_msg);
}
LOG(ERROR) << "internal message in DispatchQueue is not a valid EnqueuedMsg (created lt " << lt << ", enqueued "
<< enqueued_lt << ")";
return false;
}
auto msg_env = enq_msg->prefetch_ref();
CHECK(msg_env.not_null());
// 0. check MsgEnvelope
if (msg_env->get_level() != 0) {
LOG(ERROR) << "cannot import a message with non-zero level!";
return false;
}
if (!block::gen::t_MsgEnvelope.validate_ref(msg_env)) {
LOG(ERROR) << "MsgEnvelope from DispatchQueue is invalid according to automated checks";
return false;
}
if (!block::tlb::t_MsgEnvelope.validate_ref(msg_env)) {
LOG(ERROR) << "MsgEnvelope from DispatchQueue is invalid according to hand-written checks";
return false;
}
// 1. unpack MsgEnvelope
block::tlb::MsgEnvelope::Record_std env;
if (!tlb::unpack_cell(msg_env, env)) {
LOG(ERROR) << "cannot unpack MsgEnvelope from DispatchQueue";
return false;
}
// 2. unpack CommonMsgInfo of the message
vm::CellSlice cs{vm::NoVmOrd{}, env.msg};
if (block::gen::t_CommonMsgInfo.get_tag(cs) != block::gen::CommonMsgInfo::int_msg_info) {
LOG(ERROR) << "internal message from DispatchQueue is not in fact internal!";
return false;
}
block::gen::CommonMsgInfo::Record_int_msg_info info;
if (!tlb::unpack(cs, info)) {
LOG(ERROR) << "cannot unpack CommonMsgInfo of an internal message from DispatchQueue";
return false;
}
if (info.created_lt != lt) {
LOG(ERROR) << "internal message has lt in DispatchQueue distinct from the one in "
"its contents";
return false;
}
if (!block::tlb::validate_message_libs(env.msg)) {
LOG(ERROR) << "internal message in DispatchQueue has invalid StateInit";
return false;
}
// 2.1. check fwd_fee and fwd_fee_remaining
td::RefInt256 orig_fwd_fee = block::tlb::t_Grams.as_integer(info.fwd_fee);
if (env.fwd_fee_remaining > orig_fwd_fee) {
LOG(ERROR) << "internal message if DispatchQueue has fwd_fee_remaining=" << td::dec_string(env.fwd_fee_remaining)
<< " larger than original fwd_fee=" << td::dec_string(orig_fwd_fee);
return false;
}
// 3. extract source and destination shards
auto src_prefix = block::tlb::t_MsgAddressInt.get_prefix(info.src);
auto dest_prefix = block::tlb::t_MsgAddressInt.get_prefix(info.dest);
if (!(src_prefix.is_valid() && dest_prefix.is_valid())) {
LOG(ERROR) << "internal message in DispatchQueue has invalid source or destination address";
return false;
}
// 4. chech current and next hop shards
if (env.cur_addr != 0 || env.next_addr != 0) {
LOG(ERROR) << "internal message in DispatchQueue is expected to have zero cur_addr and next_addr";
return false;
}
// 5. calculate emitted_lt
LogicalTime emitted_lt = std::max(start_lt, last_dispatch_queue_emitted_lt_[src_addr]) + 1;
auto it = accounts.find(src_addr);
if (it != accounts.end()) {
emitted_lt = std::max(emitted_lt, it->second->last_trans_end_lt_ + 1);
}
last_dispatch_queue_emitted_lt_[src_addr] = emitted_lt;
update_max_lt(emitted_lt + 1);
env.emitted_lt = emitted_lt;
if (!block::tlb::pack_cell(msg_env, env)) {
return fatal_error("cannot pack msg envelope");
}
// 6. create NewOutMsg
block::NewOutMsg new_msg{emitted_lt, env.msg, {}, 0};
new_msg.metadata = env.metadata;
new_msg.msg_env_from_dispatch_queue = msg_env;
++unprocessed_deferred_messages_[src_addr];
LOG(INFO) << "delivering deferred message from account " << src_addr.to_hex() << ", lt=" << lt
<< ", emitted_lt=" << emitted_lt;
register_new_msg(std::move(new_msg));
msg_metadata = std::move(env.metadata);
return true;
}
/**
* Inserts an InMsg into the block's InMsgDescr.
*
@ -3517,8 +3848,9 @@ bool Collator::insert_in_msg(Ref<vm::Cell> in_msg) {
return false;
}
Ref<vm::Cell> msg = cs.prefetch_ref();
int tag = (int)cs.prefetch_ulong(3);
if (!(tag == 0 || tag == 2)) { // msg_import_ext$000 or msg_import_ihr$010 contain (Message Any) directly
int tag = block::gen::t_InMsg.get_tag(cs);
// msg_import_ext$000 or msg_import_ihr$010 contain (Message Any) directly
if (!(tag == block::gen::InMsg::msg_import_ext || tag == block::gen::InMsg::msg_import_ihr)) {
// extract Message Any from MsgEnvelope to compute correct key
auto cs2 = load_cell_slice(std::move(msg));
if (!cs2.size_refs()) {
@ -3599,11 +3931,15 @@ bool Collator::insert_out_msg(Ref<vm::Cell> out_msg, td::ConstBitPtr msg_hash) {
*
* @param msg The new outbound message to enqueue.
* @param fwd_fees_remaining The remaining forward fees for the message.
* @param enqueued_lt The logical time at which the message is enqueued.
* @param src_addr 256-bit address of the sender
* @param defer Put the message to DispatchQueue
*
* @returns True if the message was successfully enqueued, false otherwise.
*/
bool Collator::enqueue_message(block::NewOutMsg msg, td::RefInt256 fwd_fees_remaining, ton::LogicalTime enqueued_lt) {
bool Collator::enqueue_message(block::NewOutMsg msg, td::RefInt256 fwd_fees_remaining, StdSmcAddress src_addr,
bool defer) {
LogicalTime enqueued_lt = msg.lt;
CHECK(msg.msg_env_from_dispatch_queue.is_null());
// 0. unpack src_addr and dest_addr
block::gen::CommonMsgInfo::Record_int_msg_info info;
if (!tlb::unpack_cell_inexact(msg.msg, info)) {
@ -3623,18 +3959,24 @@ bool Collator::enqueue_message(block::NewOutMsg msg, td::RefInt256 fwd_fees_rema
return fatal_error("cannot perform hypercube routing for a new outbound message");
}
// 2. create a new MsgEnvelope
vm::CellBuilder cb;
CHECK(cb.store_long_bool(4, 4) // msg_envelope#4 cur_addr:.. next_addr:..
&& cb.store_long_bool(route_info.first, 8) // cur_addr:IntermediateAddress
&& cb.store_long_bool(route_info.second, 8) // next_addr:IntermediateAddress
&& block::tlb::t_Grams.store_integer_ref(cb, fwd_fees_remaining) // fwd_fee_remaining:t_Grams
&& cb.store_ref_bool(msg.msg)); // msg:^(Message Any)
Ref<vm::Cell> msg_env = cb.finalize();
block::tlb::MsgEnvelope::Record_std msg_env_rec{
defer ? 0 : route_info.first, defer ? 0 : route_info.second, fwd_fees_remaining, msg.msg, {}, msg.metadata};
Ref<vm::Cell> msg_env;
CHECK(block::tlb::pack_cell(msg_env, msg_env_rec));
// 3. create a new OutMsg
CHECK(cb.store_long_bool(1, 3) // msg_export_new$001
&& cb.store_ref_bool(msg_env) // out_msg:^MsgEnvelope
&& cb.store_ref_bool(msg.trans)); // transaction:^Transaction
Ref<vm::Cell> out_msg = cb.finalize();
vm::CellBuilder cb;
Ref<vm::Cell> out_msg;
if (defer) {
CHECK(cb.store_long_bool(0b10100, 5) // msg_export_new_defer$10100
&& cb.store_ref_bool(msg_env) // out_msg:^MsgEnvelope
&& cb.store_ref_bool(msg.trans)); // transaction:^Transaction
out_msg = cb.finalize();
} else {
CHECK(cb.store_long_bool(1, 3) // msg_export_new$001
&& cb.store_ref_bool(msg_env) // out_msg:^MsgEnvelope
&& cb.store_ref_bool(msg.trans)); // transaction:^Transaction
out_msg = cb.finalize();
}
// 4. insert OutMsg into OutMsgDescr
if (verbosity > 2) {
std::cerr << "OutMsg for a newly-generated message: ";
@ -3646,7 +3988,30 @@ bool Collator::enqueue_message(block::NewOutMsg msg, td::RefInt256 fwd_fees_rema
// 5. create EnqueuedMsg
CHECK(cb.store_long_bool(enqueued_lt) // _ enqueued_lt:uint64
&& cb.store_ref_bool(msg_env)); // out_msg:^MsgEnvelope = EnqueuedMsg;
// 6. insert EnqueuedMsg into OutMsgQueue
// 6. insert EnqueuedMsg into OutMsgQueue (or DispatchQueue)
if (defer) {
LOG(INFO) << "deferring new message from account " << workchain() << ":" << src_addr.to_hex() << ", lt=" << msg.lt;
vm::Dictionary dispatch_dict{64};
td::uint64 dispatch_dict_size;
if (!block::unpack_account_dispatch_queue(dispatch_queue_->lookup(src_addr), dispatch_dict, dispatch_dict_size)) {
return fatal_error(PSTRING() << "cannot unpack AccountDispatchQueue for account " << src_addr.to_hex());
}
td::BitArray<64> key;
key.store_ulong(msg.lt);
if (!dispatch_dict.set_builder(key, cb, vm::Dictionary::SetMode::Add)) {
return fatal_error(PSTRING() << "cannot add message to AccountDispatchQueue for account " << src_addr.to_hex()
<< ", lt=" << msg.lt);
}
++dispatch_dict_size;
dispatch_queue_->set(src_addr, block::pack_account_dispatch_queue(dispatch_dict, dispatch_dict_size));
++dispatch_queue_ops_;
if (!(dispatch_queue_ops_ & 63)) {
return block_limit_status_->add_proof(dispatch_queue_->get_root_cell());
}
return true;
}
auto next_hop = block::interpolate_addr(src_prefix, dest_prefix, route_info.second);
td::BitArray<32 + 64 + 256> key;
key.bits().store_int(next_hop.workchain, 32);
@ -3680,7 +4045,7 @@ bool Collator::process_new_messages(bool enqueue_only) {
block::NewOutMsg msg = new_msgs.top();
new_msgs.pop();
block_limit_status_->extra_out_msgs--;
if (block_full_ && !enqueue_only) {
if ((block_full_ || have_unprocessed_account_dispatch_queue_) && !enqueue_only) {
LOG(INFO) << "BLOCK FULL, enqueue all remaining new messages";
enqueue_only = true;
}
@ -3713,11 +4078,17 @@ void Collator::register_new_msg(block::NewOutMsg new_msg) {
* Registers new messages that were created in the transaction.
*
* @param trans The transaction containing the messages.
* @param msg_metadata Metadata of the new messages.
*/
void Collator::register_new_msgs(block::transaction::Transaction& trans) {
void Collator::register_new_msgs(block::transaction::Transaction& trans,
td::optional<block::MsgMetadata> msg_metadata) {
CHECK(trans.root.not_null());
for (unsigned i = 0; i < trans.out_msgs.size(); i++) {
register_new_msg(trans.extract_out_msg_ext(i));
block::NewOutMsg msg = trans.extract_out_msg_ext(i);
if (msg_metadata_enabled_) {
msg.metadata = msg_metadata;
}
register_new_msg(std::move(msg));
}
}
@ -4617,9 +4988,27 @@ bool Collator::compute_out_msg_queue_info(Ref<vm::Cell>& out_msg_queue_info) {
rt->print_rec(std::cerr);
}
vm::CellBuilder cb;
// out_msg_queue_extra#0 dispatch_queue:DispatchQueue out_queue_size:(Maybe uint48) = OutMsgQueueExtra;
// ... extra:(Maybe OutMsgQueueExtra)
if (!dispatch_queue_->is_empty() || store_out_msg_queue_size_) {
if (!(cb.store_long_bool(1, 1) && cb.store_long_bool(0, 4) && dispatch_queue_->append_dict_to_bool(cb))) {
return false;
}
if (!(cb.store_bool_bool(store_out_msg_queue_size_) &&
(!store_out_msg_queue_size_ || cb.store_long_bool(out_msg_queue_size_, 48)))) {
return false;
}
} else {
if (!cb.store_long_bool(0, 1)) {
return false;
}
}
vm::CellSlice maybe_extra = cb.as_cellslice();
cb.reset();
return register_out_msg_queue_op(true) && out_msg_queue_->append_dict_to_bool(cb) // _ out_queue:OutMsgQueue
&& processed_upto_->pack(cb) // proc_info:ProcessedInfo
&& ihr_pending->append_dict_to_bool(cb) // ihr_pending:IhrPendingInfo
&& cb.append_cellslice_bool(maybe_extra) // extra:(Maybe OutMsgQueueExtra)
&& cb.finalize_to(out_msg_queue_info);
}

View file

@ -287,6 +287,9 @@ void LiteQuery::perform() {
[&](lite_api::liteServer_getOutMsgQueueSizes& q) {
this->perform_getOutMsgQueueSizes(q.mode_ & 1 ? ShardIdFull(q.wc_, q.shard_) : td::optional<ShardIdFull>());
},
[&](lite_api::liteServer_getBlockOutMsgQueueSize& q) {
this->perform_getBlockOutMsgQueueSize(q.mode_, create_block_id(q.id_));
},
[&](auto& obj) { this->abort_query(td::Status::Error(ErrorCode::protoviolation, "unknown query")); }));
}
@ -2376,6 +2379,45 @@ void LiteQuery::perform_listBlockTransactions(BlockIdExt blkid, int mode, int co
request_block_data(blkid);
}
static td::Result<tl_object_ptr<lite_api::liteServer_transactionMetadata>> get_in_msg_metadata(
const Ref<vm::Cell>& in_msg_descr_root, const Ref<vm::Cell>& trans_root) {
vm::AugmentedDictionary in_msg_descr{vm::load_cell_slice_ref(in_msg_descr_root), 256, block::tlb::aug_InMsgDescr};
block::gen::Transaction::Record transaction;
if (!block::tlb::unpack_cell(trans_root, transaction)) {
return td::Status::Error("invalid Transaction in block");
}
Ref<vm::Cell> msg = transaction.r1.in_msg->prefetch_ref();
if (msg.is_null()) {
return nullptr;
}
td::Bits256 in_msg_hash = msg->get_hash().bits();
Ref<vm::CellSlice> in_msg = in_msg_descr.lookup(in_msg_hash);
if (in_msg.is_null()) {
return td::Status::Error(PSTRING() << "no InMsg in InMsgDescr for message with hash " << in_msg_hash.to_hex());
}
int tag = block::gen::t_InMsg.get_tag(*in_msg);
if (tag != block::gen::InMsg::msg_import_imm && tag != block::gen::InMsg::msg_import_fin &&
tag != block::gen::InMsg::msg_import_deferred_fin) {
return nullptr;
}
Ref<vm::Cell> msg_env = in_msg->prefetch_ref();
if (msg_env.is_null()) {
return td::Status::Error(PSTRING() << "no MsgEnvelope in InMsg for message with hash " << in_msg_hash.to_hex());
}
block::tlb::MsgEnvelope::Record_std env;
if (!block::tlb::unpack_cell(std::move(msg_env), env)) {
return td::Status::Error(PSTRING() << "failed to unpack MsgEnvelope for message with hash " << in_msg_hash.to_hex());
}
if (!env.metadata) {
return nullptr;
}
block::MsgMetadata& metadata = env.metadata.value();
return create_tl_object<lite_api::liteServer_transactionMetadata>(
0, metadata.depth,
create_tl_object<lite_api::liteServer_accountId>(metadata.initiator_wc, metadata.initiator_addr),
metadata.initiator_lt);
}
void LiteQuery::finish_listBlockTransactions(int mode, int req_count) {
LOG(INFO) << "completing a listBlockTransactions(" << base_blk_id_.to_str() << ", " << mode << ", " << req_count
<< ", " << acc_addr_.to_hex() << ", " << trans_lt_ << ") liteserver query";
@ -2395,6 +2437,8 @@ void LiteQuery::finish_listBlockTransactions(int mode, int req_count) {
acc_addr_.set_ones();
trans_lt_ = ~0ULL;
}
bool with_metadata = mode & 256;
mode &= ~256;
std::vector<tl_object_ptr<lite_api::liteServer_transactionId>> result;
bool eof = false;
ton::LogicalTime reverse = (mode & 64) ? ~0ULL : 0;
@ -2448,8 +2492,18 @@ void LiteQuery::finish_listBlockTransactions(int mode, int req_count) {
trans_lt_ = reverse;
break;
}
result.push_back(create_tl_object<lite_api::liteServer_transactionId>(mode, cur_addr, cur_trans.to_long(),
tvalue->get_hash().bits()));
tl_object_ptr<lite_api::liteServer_transactionMetadata> metadata;
if (with_metadata) {
auto r_metadata = get_in_msg_metadata(extra.in_msg_descr, tvalue);
if (r_metadata.is_error()) {
fatal_error(r_metadata.move_as_error());
return;
}
metadata = r_metadata.move_as_ok();
}
result.push_back(create_tl_object<lite_api::liteServer_transactionId>(
mode | (metadata ? 256 : 0), cur_addr, cur_trans.to_long(), tvalue->get_hash().bits(),
std::move(metadata)));
++count;
}
}
@ -2484,6 +2538,36 @@ void LiteQuery::perform_listBlockTransactionsExt(BlockIdExt blkid, int mode, int
request_block_data(blkid);
}
static td::Status process_all_in_msg_metadata(const Ref<vm::Cell>& in_msg_descr_root,
const std::vector<Ref<vm::Cell>>& trans_roots) {
vm::AugmentedDictionary in_msg_descr{vm::load_cell_slice_ref(in_msg_descr_root), 256, block::tlb::aug_InMsgDescr};
for (const Ref<vm::Cell>& trans_root : trans_roots) {
block::gen::Transaction::Record transaction;
if (!block::tlb::unpack_cell(trans_root, transaction)) {
return td::Status::Error("invalid Transaction in block");
}
Ref<vm::Cell> msg = transaction.r1.in_msg->prefetch_ref();
if (msg.is_null()) {
continue;
}
td::Bits256 in_msg_hash = msg->get_hash().bits();
Ref<vm::CellSlice> in_msg = in_msg_descr.lookup(in_msg_hash);
if (in_msg.is_null()) {
return td::Status::Error(PSTRING() << "no InMsg in InMsgDescr for message with hash " << in_msg_hash.to_hex());
}
int tag = block::gen::t_InMsg.get_tag(*in_msg);
if (tag == block::gen::InMsg::msg_import_imm || tag == block::gen::InMsg::msg_import_fin ||
tag == block::gen::InMsg::msg_import_deferred_fin) {
Ref<vm::Cell> msg_env = in_msg->prefetch_ref();
if (msg_env.is_null()) {
return td::Status::Error(PSTRING() << "no MsgEnvelope in InMsg for message with hash " << in_msg_hash.to_hex());
}
vm::load_cell_slice(msg_env);
}
}
return td::Status::OK();
}
void LiteQuery::finish_listBlockTransactionsExt(int mode, int req_count) {
LOG(INFO) << "completing a listBlockTransactionsExt(" << base_blk_id_.to_str() << ", " << mode << ", " << req_count
<< ", " << acc_addr_.to_hex() << ", " << trans_lt_ << ") liteserver query";
@ -2495,6 +2579,10 @@ void LiteQuery::finish_listBlockTransactionsExt(int mode, int req_count) {
CHECK(rhash == base_blk_id_.root_hash);
vm::MerkleProofBuilder pb;
auto virt_root = block_root;
if (mode & 256) {
// with msg metadata in proof
mode |= 32;
}
if (mode & 32) {
// proof requested
virt_root = pb.init(std::move(virt_root));
@ -2560,6 +2648,13 @@ void LiteQuery::finish_listBlockTransactionsExt(int mode, int req_count) {
++count;
}
}
if (mode & 256) {
td::Status S = process_all_in_msg_metadata(extra.in_msg_descr, trans_roots);
if (S.is_error()) {
fatal_error(S.move_as_error());
return;
}
}
} catch (vm::VmError err) {
fatal_error("error while parsing AccountBlocks of block "s + base_blk_id_.to_str() + " : " + err.get_msg());
return;
@ -3252,7 +3347,7 @@ void LiteQuery::continue_getOutMsgQueueSizes(td::optional<ShardIdFull> shard, Re
auto ig = mp.init_guard();
for (size_t i = 0; i < blocks.size(); ++i) {
td::actor::send_closure(manager_, &ValidatorManager::get_out_msg_queue_size, blocks[i],
[promise = ig.get_promise(), res, i, id = blocks[i]](td::Result<td::uint32> R) mutable {
[promise = ig.get_promise(), res, i, id = blocks[i]](td::Result<td::uint64> R) mutable {
TRY_RESULT_PROMISE(promise, value, std::move(R));
res->at(i) = create_tl_object<lite_api::liteServer_outMsgQueueSize>(
create_tl_lite_block_id(id), value);
@ -3271,6 +3366,73 @@ void LiteQuery::continue_getOutMsgQueueSizes(td::optional<ShardIdFull> shard, Re
});
}
void LiteQuery::perform_getBlockOutMsgQueueSize(int mode, BlockIdExt blkid) {
LOG(INFO) << "started a getBlockOutMsgQueueSize(" << blkid.to_str() << ", " << mode << ") liteserver query";
mode_ = mode;
if (!blkid.is_valid_full()) {
fatal_error("invalid BlockIdExt");
return;
}
set_continuation([=]() -> void { finish_getBlockOutMsgQueueSize(); });
request_block_data_state(blkid);
}
void LiteQuery::finish_getBlockOutMsgQueueSize() {
LOG(INFO) << "completing getBlockOutNsgQueueSize() query";
bool with_proof = mode_ & 1;
Ref<vm::Cell> state_root = state_->root_cell();
vm::MerkleProofBuilder pb;
if (with_proof) {
pb = vm::MerkleProofBuilder{state_root};
state_root = pb.root();
}
block::gen::ShardStateUnsplit::Record sstate;
block::gen::OutMsgQueueInfo::Record out_msg_queue_info;
if (!tlb::unpack_cell(state_root, sstate) || !tlb::unpack_cell(sstate.out_msg_queue_info, out_msg_queue_info)) {
fatal_error("cannot unpack shard state");
return;
}
vm::CellSlice& extra_slice = out_msg_queue_info.extra.write();
if (extra_slice.fetch_long(1) == 0) {
fatal_error("no out_msg_queue_size in shard state");
return;
}
block::gen::OutMsgQueueExtra::Record out_msg_queue_extra;
if (!tlb::unpack(extra_slice, out_msg_queue_extra)) {
fatal_error("cannot unpack OutMsgQueueExtra");
return;
}
vm::CellSlice& size_slice = out_msg_queue_extra.out_queue_size.write();
if (size_slice.fetch_long(1) == 0) {
fatal_error("no out_msg_queue_size in shard state");
return;
}
td::uint64 size = size_slice.prefetch_ulong(48);
td::BufferSlice proof;
if (with_proof) {
Ref<vm::Cell> proof1, proof2;
if (!make_state_root_proof(proof1)) {
return;
}
if (!pb.extract_proof_to(proof2)) {
fatal_error("unknown error creating Merkle proof");
return;
}
auto r_proof = vm::std_boc_serialize_multi({std::move(proof1), std::move(proof2)});
if (r_proof.is_error()) {
fatal_error(r_proof.move_as_error());
return;
}
proof = r_proof.move_as_ok();
}
LOG(INFO) << "getBlockOutMsgQueueSize(" << blk_id_.to_str() << ", " << mode_ << ") query completed";
auto b = ton::create_serialize_tl_object<ton::lite_api::liteServer_blockOutMsgQueueSize>(
mode_, ton::create_tl_lite_block_id(blk_id_), size, std::move(proof));
finish_query(std::move(b));
}
void LiteQuery::perform_nonfinal_getCandidate(td::Bits256 source, BlockIdExt blkid, td::Bits256 collated_data_hash) {
LOG(INFO) << "started a nonfinal.getCandidate liteserver query";
td::actor::send_closure_later(

View file

@ -170,6 +170,8 @@ class LiteQuery : public td::actor::Actor {
std::vector<std::pair<BlockIdExt, td::BufferSlice>> result);
void perform_getOutMsgQueueSizes(td::optional<ShardIdFull> shard);
void continue_getOutMsgQueueSizes(td::optional<ShardIdFull> shard, Ref<MasterchainState> state);
void perform_getBlockOutMsgQueueSize(int mode, BlockIdExt blkid);
void finish_getBlockOutMsgQueueSize();
void perform_nonfinal_getCandidate(td::Bits256 source, BlockIdExt blkid, td::Bits256 collated_data_hash);
void perform_nonfinal_getValidatorGroups(int mode, ShardIdFull shard);

File diff suppressed because it is too large Load diff

View file

@ -112,7 +112,8 @@ class ValidateQuery : public td::actor::Actor {
return SUPPORTED_VERSION;
}
static constexpr long long supported_capabilities() {
return ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion | ton::capShortDequeue;
return ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion | ton::capShortDequeue |
ton::capStoreOutMsgQueueSize | ton::capMsgMetadata | ton::capDeferMessages;
}
public:
@ -227,9 +228,21 @@ class ValidateQuery : public td::actor::Actor {
bool inbound_queues_empty_{false};
std::vector<std::tuple<Bits256, LogicalTime, LogicalTime>> msg_proc_lt_;
std::vector<std::tuple<Bits256, LogicalTime, LogicalTime>> msg_emitted_lt_;
std::vector<std::tuple<Bits256, Bits256, bool>> lib_publishers_, lib_publishers2_;
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_;
std::set<StdSmcAddress> account_expected_defer_all_messages_;
td::uint64 old_out_msg_queue_size_ = 0, new_out_msg_queue_size_ = 0;
bool msg_metadata_enabled_ = false;
bool deferring_messages_enabled_ = false;
bool store_out_msg_queue_size_ = false;
bool have_unprocessed_account_dispatch_queue_ = false;
td::PerfWarningTimer perf_timer_;
static constexpr td::uint32 priority() {
@ -309,6 +322,8 @@ class ValidateQuery : public td::actor::Actor {
bool check_cur_validator_set();
bool check_mc_validator_info(bool update_mc_cc);
bool check_utime_lt();
bool prepare_out_msg_queue_size();
void got_out_queue_size(size_t i, td::Result<td::uint64> res);
bool fix_one_processed_upto(block::MsgProcessedUpto& proc, ton::ShardIdFull owner, bool allow_cur = false);
bool fix_processed_upto(block::MsgProcessedUptoCollection& upto, bool allow_cur = false);
@ -330,6 +345,9 @@ class ValidateQuery : public td::actor::Actor {
bool precheck_one_message_queue_update(td::ConstBitPtr out_msg_id, Ref<vm::CellSlice> old_value,
Ref<vm::CellSlice> new_value);
bool precheck_message_queue_update();
bool check_account_dispatch_queue_update(td::Bits256 addr, Ref<vm::CellSlice> old_queue_csr,
Ref<vm::CellSlice> new_queue_csr);
bool unpack_dispatch_queue_update();
bool update_max_processed_lt_hash(ton::LogicalTime lt, const ton::Bits256& hash);
bool update_min_enqueued_lt_hash(ton::LogicalTime lt, const ton::Bits256& hash);
bool check_imported_message(Ref<vm::Cell> msg_env);
@ -338,6 +356,7 @@ class ValidateQuery : public td::actor::Actor {
bool check_in_msg_descr();
bool check_out_msg(td::ConstBitPtr key, Ref<vm::CellSlice> out_msg);
bool check_out_msg_descr();
bool check_dispatch_queue_update();
bool check_processed_upto();
bool check_neighbor_outbound_message(Ref<vm::CellSlice> enq_msg, ton::LogicalTime lt, td::ConstBitPtr key,
const block::McShardDescr& src_nb, bool& unprocessed);

View file

@ -384,7 +384,7 @@ class ValidatorManagerImpl : public ValidatorManager {
void log_new_validator_group_stats(validatorsession::NewValidatorGroupStats stats) override {
UNREACHABLE();
}
void get_out_msg_queue_size(BlockIdExt block_id, td::Promise<td::uint32> promise) override {
void get_out_msg_queue_size(BlockIdExt block_id, td::Promise<td::uint64> promise) override {
if (queue_size_counter_.empty()) {
queue_size_counter_ =
td::actor::create_actor<QueueSizeCounter>("queuesizecounter", td::Ref<MasterchainState>{}, actor_id(this));

View file

@ -446,7 +446,7 @@ class ValidatorManagerImpl : public ValidatorManager {
void log_new_validator_group_stats(validatorsession::NewValidatorGroupStats stats) override {
UNREACHABLE();
}
void get_out_msg_queue_size(BlockIdExt block_id, td::Promise<td::uint32> promise) override {
void get_out_msg_queue_size(BlockIdExt block_id, td::Promise<td::uint64> promise) override {
if (queue_size_counter_.empty()) {
queue_size_counter_ =
td::actor::create_actor<QueueSizeCounter>("queuesizecounter", td::Ref<MasterchainState>{}, actor_id(this));

View file

@ -590,7 +590,7 @@ class ValidatorManagerImpl : public ValidatorManager {
void update_options(td::Ref<ValidatorManagerOptions> opts) override;
void get_out_msg_queue_size(BlockIdExt block_id, td::Promise<td::uint32> promise) override {
void get_out_msg_queue_size(BlockIdExt block_id, td::Promise<td::uint64> promise) override {
if (queue_size_counter_.empty()) {
if (last_masterchain_state_.is_null()) {
promise.set_error(td::Status::Error(ErrorCode::notready, "not ready"));

View file

@ -23,8 +23,8 @@
namespace ton::validator {
static td::Result<td::uint32> calc_queue_size(const td::Ref<ShardState> &state) {
td::uint32 size = 0;
static td::Result<td::uint64> calc_queue_size(const td::Ref<ShardState> &state) {
td::uint64 size = 0;
TRY_RESULT(outq_descr, state->message_queue());
block::gen::OutMsgQueueInfo::Record qinfo;
if (!tlb::unpack_cell(outq_descr->root_cell(), qinfo)) {
@ -41,8 +41,8 @@ static td::Result<td::uint32> calc_queue_size(const td::Ref<ShardState> &state)
return size;
}
static td::Result<td::uint32> recalc_queue_size(const td::Ref<ShardState> &state, const td::Ref<ShardState> &prev_state,
td::uint32 prev_size) {
static td::Result<td::uint64> recalc_queue_size(const td::Ref<ShardState> &state, const td::Ref<ShardState> &prev_state,
td::uint64 prev_size) {
TRY_RESULT(outq_descr, state->message_queue());
block::gen::OutMsgQueueInfo::Record qinfo;
if (!tlb::unpack_cell(outq_descr->root_cell(), qinfo)) {
@ -56,7 +56,7 @@ static td::Result<td::uint32> recalc_queue_size(const td::Ref<ShardState> &state
return td::Status::Error("invalid message queue");
}
vm::AugmentedDictionary prev_queue{prev_qinfo.out_queue->prefetch_ref(0), 352, block::tlb::aug_OutMsgQueue};
td::uint32 add = 0, rem = 0;
td::uint64 add = 0, rem = 0;
bool ok = prev_queue.scan_diff(
queue, [&](td::ConstBitPtr, int, td::Ref<vm::CellSlice> prev_val, td::Ref<vm::CellSlice> new_val) -> bool {
if (prev_val.not_null()) {
@ -88,11 +88,11 @@ void QueueSizeCounter::start_up() {
alarm();
}
void QueueSizeCounter::get_queue_size(BlockIdExt block_id, td::Promise<td::uint32> promise) {
void QueueSizeCounter::get_queue_size(BlockIdExt block_id, td::Promise<td::uint64> promise) {
get_queue_size_ex(block_id, simple_mode_ || is_block_too_old(block_id), std::move(promise));
}
void QueueSizeCounter::get_queue_size_ex(ton::BlockIdExt block_id, bool calc_whole, td::Promise<td::uint32> promise) {
void QueueSizeCounter::get_queue_size_ex(ton::BlockIdExt block_id, bool calc_whole, td::Promise<td::uint64> promise) {
Entry &entry = results_[block_id];
if (entry.done_) {
promise.set_result(entry.queue_size_);
@ -152,12 +152,12 @@ void QueueSizeCounter::get_queue_size_cont(BlockHandle handle, td::Ref<ShardStat
}
auto prev_block_id = handle->one_prev(true);
get_queue_size(prev_block_id, [=, SelfId = actor_id(this), manager = manager_](td::Result<td::uint32> R) {
get_queue_size(prev_block_id, [=, SelfId = actor_id(this), manager = manager_](td::Result<td::uint64> R) {
if (R.is_error()) {
td::actor::send_closure(SelfId, &QueueSizeCounter::on_error, state->get_block_id(), R.move_as_error());
return;
}
td::uint32 prev_size = R.move_as_ok();
td::uint64 prev_size = R.move_as_ok();
td::actor::send_closure(
manager, &ValidatorManager::wait_block_state_short, prev_block_id, 0, td::Timestamp::in(10.0),
[=](td::Result<td::Ref<ShardState>> R) {
@ -171,7 +171,7 @@ void QueueSizeCounter::get_queue_size_cont(BlockHandle handle, td::Ref<ShardStat
}
void QueueSizeCounter::get_queue_size_cont2(td::Ref<ShardState> state, td::Ref<ShardState> prev_state,
td::uint32 prev_size) {
td::uint64 prev_size) {
BlockIdExt block_id = state->get_block_id();
Entry &entry = results_[block_id];
CHECK(entry.started_);
@ -252,7 +252,7 @@ void QueueSizeCounter::process_top_shard_blocks_cont(td::Ref<MasterchainState> s
void QueueSizeCounter::get_queue_size_ex_retry(BlockIdExt block_id, bool calc_whole, td::Promise<td::Unit> promise) {
get_queue_size_ex(block_id, calc_whole,
[=, promise = std::move(promise), SelfId = actor_id(this)](td::Result<td::uint32> R) mutable {
[=, promise = std::move(promise), SelfId = actor_id(this)](td::Result<td::uint64> R) mutable {
if (R.is_error()) {
LOG(WARNING) << "Failed to calculate queue size for block " << block_id.to_str() << ": "
<< R.move_as_error();

View file

@ -26,7 +26,7 @@ class QueueSizeCounter : public td::actor::Actor {
}
void start_up() override;
void get_queue_size(BlockIdExt block_id, td::Promise<td::uint32> promise);
void get_queue_size(BlockIdExt block_id, td::Promise<td::uint64> promise);
void alarm() override;
private:
@ -42,14 +42,14 @@ class QueueSizeCounter : public td::actor::Actor {
bool started_ = false;
bool done_ = false;
bool calc_whole_ = false;
td::uint32 queue_size_ = 0;
std::vector<td::Promise<td::uint32>> promises_;
td::uint64 queue_size_ = 0;
std::vector<td::Promise<td::uint64>> promises_;
};
std::map<BlockIdExt, Entry> results_;
void get_queue_size_ex(BlockIdExt block_id, bool calc_whole, td::Promise<td::uint32> promise);
void get_queue_size_ex(BlockIdExt block_id, bool calc_whole, td::Promise<td::uint64> promise);
void get_queue_size_cont(BlockHandle handle, td::Ref<ShardState> state);
void get_queue_size_cont2(td::Ref<ShardState> state, td::Ref<ShardState> prev_state, td::uint32 prev_size);
void get_queue_size_cont2(td::Ref<ShardState> state, td::Ref<ShardState> prev_state, td::uint64 prev_size);
void on_error(BlockIdExt block_id, td::Status error);
void process_top_shard_blocks();

View file

@ -249,7 +249,7 @@ class ValidatorManagerInterface : public td::actor::Actor {
virtual void prepare_perf_timer_stats(td::Promise<std::vector<PerfTimerStats>> promise) = 0;
virtual void add_perf_timer_stat(std::string name, double duration) = 0;
virtual void get_out_msg_queue_size(BlockIdExt block_id, td::Promise<td::uint32> promise) = 0;
virtual void get_out_msg_queue_size(BlockIdExt block_id, td::Promise<td::uint64> promise) = 0;
virtual void update_options(td::Ref<ValidatorManagerOptions> opts) = 0;
};