1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-13 11:42:18 +00:00
ton/tl-utils/lite-utils.cpp
EmelyanenkoK 0daee1d887
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>
2024-06-27 16:12:23 +03:00

172 lines
5.5 KiB
C++

/*
This file is part of TON Blockchain Library.
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.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "tl-utils.hpp"
#include "tl/tl_object_store.h"
#include "auto/tl/lite_api.hpp"
#include "td/utils/tl_storers.h"
#include "td/utils/crypto.h"
#include "crypto/common/bitstring.h"
#include <map>
namespace ton {
td::BufferSlice serialize_tl_object(const lite_api::Object *T, bool boxed, td::BufferSlice &&suffix) {
td::TlStorerCalcLength X;
T->store(X);
auto l = X.get_length() + (boxed ? 4 : 0);
auto len = l + suffix.size();
td::BufferSlice B(len);
td::TlStorerUnsafe Y(B.as_slice().ubegin());
if (boxed) {
Y.store_binary(T->get_id());
}
T->store(Y);
auto S = B.as_slice();
S.remove_prefix(l);
S.copy_from(suffix.as_slice());
suffix.clear();
return B;
}
td::BufferSlice serialize_tl_object(const lite_api::Object *T, bool boxed) {
td::TlStorerCalcLength X;
T->store(X);
auto l = X.get_length() + (boxed ? 4 : 0);
auto len = l;
td::BufferSlice B(len);
td::TlStorerUnsafe Y(B.as_slice().ubegin());
if (boxed) {
Y.store_binary(T->get_id());
}
T->store(Y);
return B;
}
td::BufferSlice serialize_tl_object(const lite_api::Function *T, bool boxed) {
CHECK(boxed);
td::TlStorerCalcLength X;
T->store(X);
auto l = X.get_length();
auto len = l;
td::BufferSlice B(len);
td::TlStorerUnsafe Y(B.as_slice().ubegin());
T->store(Y);
return B;
}
td::BufferSlice serialize_tl_object(const lite_api::Function *T, bool boxed, td::BufferSlice &&suffix) {
CHECK(boxed);
td::TlStorerCalcLength X;
T->store(X);
auto l = X.get_length();
auto len = l + suffix.size();
td::BufferSlice B(len);
td::TlStorerUnsafe Y(B.as_slice().ubegin());
T->store(Y);
auto S = B.as_slice();
S.remove_prefix(l);
S.copy_from(suffix.as_slice());
suffix.clear();
return B;
}
td::UInt256 get_tl_object_sha256(const lite_api::Object *T) {
td::TlStorerCalcLength X;
T->store(X);
auto len = X.get_length() + 4;
td::BufferSlice B(len);
td::TlStorerUnsafe Y(B.as_slice().ubegin());
Y.store_binary(T->get_id());
T->store(Y);
td::UInt256 id256;
td::sha256(B.as_slice(), id256.as_slice());
return id256;
}
td::Bits256 get_tl_object_sha_bits256(const lite_api::Object *T) {
td::TlStorerCalcLength X;
T->store(X);
auto len = X.get_length() + 4;
td::BufferSlice B(len);
td::TlStorerUnsafe Y(B.as_slice().ubegin());
Y.store_binary(T->get_id());
T->store(Y);
td::Bits256 id256;
td::sha256(B.as_slice(), id256.as_slice());
return id256;
}
std::string lite_query_name_by_id(int id) {
static std::map<int, std::string> names = {
{lite_api::liteServer_getMasterchainInfo::ID, "getMasterchainInfo"},
{lite_api::liteServer_getMasterchainInfoExt::ID, "getMasterchainInfoExt"},
{lite_api::liteServer_getTime::ID, "getTime"},
{lite_api::liteServer_getVersion::ID, "getVersion"},
{lite_api::liteServer_getBlock::ID, "getBlock"},
{lite_api::liteServer_getState::ID, "getState"},
{lite_api::liteServer_getBlockHeader::ID, "getBlockHeader"},
{lite_api::liteServer_sendMessage::ID, "sendMessage"},
{lite_api::liteServer_getAccountState::ID, "getAccountState"},
{lite_api::liteServer_getAccountStatePrunned::ID, "getAccountStatePrunned"},
{lite_api::liteServer_runSmcMethod::ID, "runSmcMethod"},
{lite_api::liteServer_getShardInfo::ID, "getShardInfo"},
{lite_api::liteServer_getAllShardsInfo::ID, "getAllShardsInfo"},
{lite_api::liteServer_getOneTransaction::ID, "getOneTransaction"},
{lite_api::liteServer_getTransactions::ID, "getTransactions"},
{lite_api::liteServer_lookupBlock::ID, "lookupBlock"},
{lite_api::liteServer_lookupBlockWithProof::ID, "lookupBlockWithProof"},
{lite_api::liteServer_listBlockTransactions::ID, "listBlockTransactions"},
{lite_api::liteServer_listBlockTransactionsExt::ID, "listBlockTransactionsExt"},
{lite_api::liteServer_getBlockProof::ID, "getBlockProof"},
{lite_api::liteServer_getConfigAll::ID, "getConfigAll"},
{lite_api::liteServer_getConfigParams::ID, "getConfigParams"},
{lite_api::liteServer_getValidatorStats::ID, "getValidatorStats"},
{lite_api::liteServer_getLibraries::ID, "getLibraries"},
{lite_api::liteServer_getLibrariesWithProof::ID, "getLibrariesWithProof"},
{lite_api::liteServer_getShardBlockProof::ID, "getShardBlockProof"},
{lite_api::liteServer_getOutMsgQueueSizes::ID, "getOutMsgQueueSizes"},
{lite_api::liteServer_getBlockOutMsgQueueSize::ID, "getBlockOutMsgQueueSize"},
{lite_api::liteServer_nonfinal_getCandidate::ID, "nonfinal.getCandidate"},
{lite_api::liteServer_nonfinal_getValidatorGroups::ID, "nonfinal.getValidatorGroups"}};
auto it = names.find(id);
if (it == names.end()) {
return "unknown";
}
return it->second;
}
} // namespace ton