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

Merge branch 'testnet' into block-generation

This commit is contained in:
SpyCheese 2024-02-01 19:29:25 +03:00
commit f4fd3ff3be
246 changed files with 7895 additions and 5430 deletions

File diff suppressed because it is too large Load diff

View file

@ -13,11 +13,12 @@ Test_Fift_test_bls_ops_default fb0a81d4f247ab806318b051d12158f7f1aacc5513db5f8cb
Test_Fift_test_deep_stack_ops_default df812efbadfffa8a3f553416f68c8c4435bac07266f84562cf98fe5f0dd62a52
Test_Fift_test_default 4e44b3382963ec89f7b5c8f2ebd85da3bc8aebad5b49f5b11b14075061477b4d
Test_Fift_test_dict_default a9c8cbcfdece5573185022cea07f59f1bc404e5d879e5157a5745757f8ee0525
Test_Fift_test_disasm_default dacaa555f5f217b2373e01e3bcd59634e480f5759dcc43edbdef35273ae38492
Test_Fift_test_disasm_default 412cf37d37c5d9d81f44dbf4e3d3e7cda173c23b890614eb8a3bc5f2b92f13e6
Test_Fift_test_fiftext_default 2b0db5d4d4bfbc705b959cc787540d7b3a21a71469eac54756e76953f0d9afca
Test_Fift_test_fixed_default 278a19d56b773102caf5c1fe2997ea6c8d0d9e720eff8503feede6398a197eec
Test_Fift_test_hash_ext_default 686fc5680feca5b3bb207768215b27f6872a95128762dee0d7f2c88bc492d62d
Test_Fift_test_hmap_default c269246882039824bb5822e896c3e6e82ef8e1251b6b251f5af8ea9fb8d05067
Test_Fift_test_levels_default 9fba4a7c98aec9000f42846d6e5fd820343ba61d68f9139dd16c88ccda757cf3
Test_Fift_test_namespaces_default e6419619c51332fb5e8bf22043ef415db686c47fe24f03061e5ad831014e7c6c
Test_Fift_test_rist255_default f4d7558f200a656934f986145c19b1dedbe2ad029292a5a975576d6891e25fc4
Test_Fift_test_sort2_default 9b57d47e6a10e7d1bbb565db35400debf2f963031f434742a702ec76555a5d3a
@ -37,40 +38,40 @@ Test_Fift_testvm8_default 17c9e2205ccecfd8549328b4a501d07dde0336899a7a496e747e10
Test_Fift_testvm_default ee4cbfec76c050b6de7877cfc39817d594cd1e175b6265b76fb642e30b940437
Test_Fift_testvmprog_default e5d0b2c68ee568280877c8495be558bfd0054ca5d99a99eebb525bbeca8a65af
Test_RefInt_main_default 768493e0aef8e09a401a6d369edd1ef503a9215fb09dc460f52b27a8bde767cb
Test_VM_assert_code_not_null_default 05bc07e129181c972b976442f200de9487dee8bfb5ac53dd36ff61c5d4d4291d
Test_VM_assert_extract_minmax_key_default c352309c61bdf62ba7a0ba7280d303c88b0696fe7efa550c05feb2c662275297
Test_VM_assert_lookup_prefix_default c5b45999b46d324e4008c07e5ce671bbcd833f4e15fb21a4a5136f7b980ca6fc
Test_VM_assert_pfx_dict_lookup_default fa6e3f96b31cf2ed9a9dac6b279ec05acfedf13b8ed7b815789f167d1ed7352f
Test_VM_assert_code_not_null_default 09f75cb845e0df27f3ec92405ccb4018484711a79813fd47fe8e158762c1cb93
Test_VM_assert_extract_minmax_key_default 756337c2b2ce489243956a6608d6934ba9f76124a9435f045fc3a3b65c113d41
Test_VM_assert_lookup_prefix_default f7683f9d2010bca53b1ef20c0e82427fb04ed62fa5fea1ee986f005ecfc9a27a
Test_VM_assert_pfx_dict_lookup_default 6d7c80d94dbc6d3ae4bafa216667b95ede4f2cbd44a59384abace84270417ef8
Test_VM_bigint_default feeb473a4ac51133989e1c145d0f49defa77117d2ae8b66bd7d12e3579e91b9f
Test_VM_bug_div_short_any_default f69aca6873f75d53dd37b6952151a2d858407a04589330762827dbc96d8b7c04
Test_VM_bug_exec_dict_getnear_default db314c2e25b49c1f7f044d271e225f36da546c66242a8ab12f6afae37628a81e
Test_VM_bug_stack_overflow_default 7e0e3e96ca438ac96648d569c55213aa82154cf004e80265b1c481b1c4219719
Test_VM_infinity_loop_1_default 670beda76229922806805e558d50d8f320017c642c3e7e34a7e1f2b7edb83cee
Test_VM_infinity_loop_2_default 22d9bd8cb41ff7b6cced5825e4ab73275b2fc07b1e3cd4588de815e2e6df2963
Test_VM_memory_leak_default e10dc118f3538720a16bcbd39be9a68c3ea07f76b3d2ed5719a5e866d91f0ab3
Test_VM_memory_leak_new_default fd2eec0a1d5ae49fb5ff8ba4b938fd9d0fe330be4a07b2b8be12bab249b00d90
Test_VM_memory_leak_old_default f3076ae38d14000c021597b824d2f0e51de4f00601429ec3e23cca1b32dba844
Test_VM_oom_1_default 90862ddf3270840fbc9263c003c628ddd4a8bf6548b9bd3d53eb35a5c34bc325
Test_VM_report3_1_default 7bc6a8e66f9a0e40cd131e9829ff36fed16b464170d27c0b365a3f549df57282
Test_VM_report3_2_default 2231bc352cf431e72a84abad2261969bd5b0ee3d9051bb7a53b69fd8ea05f951
Test_VM_report3_3_default 9416187eb0600ed247795837ca820bccaffb39841bd9d2ff625816bfbba35d6d
Test_VM_report3_4_default 11661eb00ea37c68e3483a8e048f922f73070c6da8219247663e3d6471c5c0cc
Test_VM_report3_6_default 1d7be98a8b07f803e80168247459e620ce4b91df634ad896e878d21a3ed757c0
Test_VM_report3_int_overflow_1_default a0c2414ca2c9672d54409ee375a6aad6e2233306eaa3dfd33a82de3c90bba3ba
Test_VM_report3_int_overflow_2_default 01cd461802e532a6830705ad50eaa1760278737ff7beeb654e3c59ceb4aa8e2e
Test_VM_report3_loop_1_default b28b35d057a1b4fa2282d6f422ecd822b18cc4344733d923ef7b002f64bc4d72
Test_VM_report3_loop_2_default 9f8236535902b04e403d412fcf1f79e64d0f2eb25b3cc014b7d61b2d7a34b9ef
Test_VM_report3_loop_3_default 7ee05ea553c48a2476035817b9d860f614a355927c9e011b2f824dc6e5f7b0cf
Test_VM_report3_loop_4_default 4b6c2f65fda3c9e9c6660b6cbbcb1b2103c5b52870cb5daa8876bbed0ca9bbc9
Test_VM_report3_loop_5_default 0d5d504884172ef8513757d7f6b2a3870dbd28efd5960857441c032e1c67d836
Test_VM_report3_loop_6_default 5c35b92144debdb61b2020d690669bffbdd96f75ecde827fd0c75c05da22b5a0
Test_VM_report3_qnot_default dc280444c7e3886cc3412f96f44c803c45287a07fcb9c638643e21bcdfe3905d
Test_VM_simple_default f6733549069427c2beb1a85ee25635540e27aa68cb8ad101d8435e19afeae862
Test_VM_unhandled_exception_1_default 0abe2740dd3b6a6b91eb67fee573f638086fecc72653d2d81c956782186b5d78
Test_VM_unhandled_exception_2_default 5ca67db5a0e957cc106bb47b744177ca959632a352f3629df376c34cbf03d51b
Test_VM_unhandled_exception_3_default b354e897e35a1177fd66d2c6ad7d77ae33a4e18f8678a518d79fea1388853307
Test_VM_unhandled_exception_4_default 412cbfe13745fde55cdcc5e41d7b15ba4d09f0e723f8e4421ae0b7066ca07b8f
Test_VM_unhandled_exception_5_default d760e540cd9c200c207f71c540cdaf06d11c96e32ec19860b9c1046cb1e38855
Test_VM_bug_div_short_any_default 49c9588b2b25b08979016f8b7ca42ae9fa4904a1dc6a2093a7dae6dce0cdf42f
Test_VM_bug_exec_dict_getnear_default 0b0cb6c1fef773f8b5a4aab8d575ba941f3b85dd449f85051296954028e59781
Test_VM_bug_stack_overflow_default 31950eb2ed62bd1ce1c18e0031a81390ff3a3feee61ff23a09181995917137d0
Test_VM_infinity_loop_1_default 6b8cc0ff85efa6882ffdf6e9e4333967976a29c4ce32a25b42c4c53370ad3024
Test_VM_infinity_loop_2_default 4be08957dc86dfde3dfadd8c2f961ef2f1fa839788bbf7affea754115cee9e18
Test_VM_memory_leak_default da588f89f3bc3ef7496bbab61e2d993f0c84bba80bb28d9c20c6eac0f7f57dd3
Test_VM_memory_leak_new_default d25e8602c88c454ded6271d0f7afbc556820cc9942c56de9e0bd95b329f8783e
Test_VM_memory_leak_old_default 563f5a02130f231823099985c77d09913db07d2d8782edf431822f6afe4911b8
Test_VM_oom_1_default 354934173c82e4f7bca5063846abd35cb47c4fcf1c3ba8c2fd04a4b186fcbf18
Test_VM_report3_1_default 26bb43b5100e94791911a66226ec6545422749e0ea9e6279983b00ef4b506601
Test_VM_report3_2_default 07a84726217f362fd71b3ceab96112ffc7aa40ed44636cf0128205d85798c66c
Test_VM_report3_3_default 0d9a92491c88ada92283691debd123724db2b7c1bd345200a53c057032e9cc07
Test_VM_report3_4_default eb23c8e1219aed91b1b4f519efcac87018a5cf8e0ce473cfa641f8221f3c5d20
Test_VM_report3_6_default 769ce8f9bb6fb9b8619afdb8e9d621b6199466f07c37eeea8edf3c21bf05a101
Test_VM_report3_int_overflow_1_default 7aaf32ec7ace54b93d6b55f3ac9642572f348ebd64412afdda24849f8e4eb1dc
Test_VM_report3_int_overflow_2_default 572d197681654c94951280448ea3cf448613391633383c2424d719b03b6ec939
Test_VM_report3_loop_1_default c9b00b32a024c65e0a8019c86e94ee365a823ff26e2420e1797902841abab57c
Test_VM_report3_loop_2_default 3654949987ddb44d8e11e84fe907d43707eaed910b9d0ad15dd68b531df1444a
Test_VM_report3_loop_3_default c1fc7e0d160b334fe8a4735a2a9d36c3b10530edaad5c1859df88382ff82a2d9
Test_VM_report3_loop_4_default 5ad7cc51a6e553ee3d4a427229908a51692e117624838190311c7023df7a5e5b
Test_VM_report3_loop_5_default 068f81caecc344132a601259d9f73eea7089b1399793661ba1954483e0d5682c
Test_VM_report3_loop_6_default bf2e45709fceeed0192ec34af618cba3b85b90f71071e018afba686167618a90
Test_VM_report3_qnot_default 7fcbda7e3fc4853a36e6b02e9d346f039690b1879d40850f561ea4123452d3ec
Test_VM_simple_default c96d70ea853828c89cd38fcf22543289335f3086a53301a1d0f186753ba9975b
Test_VM_unhandled_exception_1_default 80fe0e4c2ae19ae73e67e4355548d0afa59ea286be2d75a91db4529618dba008
Test_VM_unhandled_exception_2_default 1362ba3a6ddbf5a30aba07ad58e8c24b0f85bdc53525e3eaa27af7248c62525a
Test_VM_unhandled_exception_3_default e381ce751cbd0e2994d7f60df7746b9ed7783198cfbcb31dccf02fafe68b6733
Test_VM_unhandled_exception_4_default 51dd501ec0514f3b388145761b252f09d6ef3e831ea450605ae30511688dd708
Test_VM_unhandled_exception_5_default 8231cfe1fb6ce6107b592f2c8f6a4eae0d123fc399163c81e8e0d5228b68bc91
Test_base64_main_default e90d541bd810871c4a81e162f1fffb555024b72807cb895414d16bc11494b789
Test_bigexp_main_default 45a1f51fb2abcc1ebf8569e1a57bebee04c334a15e03535ff5869bc9a9db8956
Test_bits256_scan_main_default 3ec7434e1cabc8e08eb2e79064e67747ffbfed177473c7873b88c144a7ed6f42

View file

@ -52,7 +52,7 @@ int main() {
td::to_integer_safe<td::uint32>("0").ensure();
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-adnl";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();

View file

@ -186,6 +186,7 @@ class CatChainInst : public td::actor::Actor {
void create_fork() {
auto height = height_ - 1; //td::Random::fast(0, height_ - 1);
LOG(WARNING) << "Creating fork, source_id=" << idx_ << ", height=" << height;
auto sum = prev_values_[height] + 1;
td::uint64 x[2];
@ -219,7 +220,7 @@ int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_INFO);
td::set_default_failure_signal_handler().ensure();
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-catchain";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();
@ -241,7 +242,8 @@ int main(int argc, char *argv[]) {
td::actor::send_closure(adnl, &ton::adnl::Adnl::register_network_manager, network_manager.get());
});
for (td::uint32 att = 0; att < 10; att++) {
for (td::uint32 att = 0; att < 20; att++) {
LOG(WARNING) << "Test #" << att;
nodes.resize(total_nodes);
scheduler.run_in_context([&] {
@ -274,8 +276,6 @@ int main(int argc, char *argv[]) {
}
});
auto t = td::Timestamp::in(1.0);
ton::catchain::CatChainSessionId unique_id;
td::Random::secure_bytes(unique_id.as_slice());
@ -287,7 +287,7 @@ int main(int argc, char *argv[]) {
}
});
t = td::Timestamp::in(10.0);
auto t = td::Timestamp::in(10.0);
while (scheduler.run(1)) {
if (t.is_in_past()) {
break;
@ -298,9 +298,12 @@ int main(int argc, char *argv[]) {
std::cout << "value=" << n.get_actor_unsafe().value() << std::endl;
}
scheduler.run_in_context([&] { td::actor::send_closure(inst[0], &CatChainInst::create_fork); });
td::uint32 fork_cnt = att < 10 ? 1 : (att - 10) / 5 + 2;
for (td::uint32 idx = 0; idx < fork_cnt; ++idx) {
scheduler.run_in_context([&] { td::actor::send_closure(inst[idx], &CatChainInst::create_fork); });
}
t = td::Timestamp::in(10.0);
t = td::Timestamp::in(1.0);
while (scheduler.run(1)) {
if (t.is_in_past()) {
break;

View file

@ -41,7 +41,7 @@
int main() {
SET_VERBOSITY_LEVEL(verbosity_INFO);
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-dht";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();

View file

@ -1,220 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU 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 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#include "adnl/adnl-ext-client.h"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <iostream>
#include <sstream>
template <std::size_t size>
std::ostream &operator<<(std::ostream &stream, const td::UInt<size> &x) {
for (size_t i = 0; i < size / 8; i++) {
stream << td::format::hex_digit((x.raw[i] >> 4) & 15) << td::format::hex_digit(x.raw[i] & 15);
}
return stream;
}
class TestNode : public td::actor::Actor {
private:
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
td::actor::ActorOwn<ton::adnl::AdnlExtClient> client_;
std::unique_ptr<ton::adnl::AdnlExtClient::Callback> make_callback() {
class Callback : public ton::adnl::AdnlExtClient::Callback {
public:
void on_ready() override {
td::actor::send_closure(id_, &TestNode::conn_ready);
}
void on_stop_ready() override {
td::actor::send_closure(id_, &TestNode::conn_closed);
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
bool ready_ = false;
std::string db_root_;
public:
void conn_ready() {
LOG(ERROR) << "conn ready";
ready_ = true;
}
void conn_closed() {
ready_ = false;
}
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void set_db_root(std::string db_root) {
db_root_ = db_root;
}
void start_up() override {
}
void alarm() override {
if (ready_ && !client_.empty()) {
LOG(ERROR) << "sending query";
auto P = td::PromiseCreator::lambda([](td::Result<td::BufferSlice> R) {
if (R.is_error()) {
LOG(ERROR) << "failed query: " << R.move_as_error();
return;
}
auto F = ton::fetch_tl_object<ton::ton_api::Object>(R.move_as_ok(), true);
if (F.is_error()) {
LOG(ERROR) << "failed to pasrse answer: " << F.move_as_error();
return;
}
auto obj = F.move_as_ok();
LOG(ERROR) << "got answer: " << ton::ton_api::to_string(obj);
});
td::BufferSlice b = ton::serialize_tl_object(ton::create_tl_object<ton::ton_api::getTestObject>(), true);
td::actor::send_closure(client_, &ton::adnl::AdnlExtClient::send_query, "query", std::move(b),
td::Timestamp::in(10.0), std::move(P));
}
alarm_timestamp() = td::Timestamp::in(2.0);
}
TestNode() {
}
void run() {
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
CHECK(gc.liteclients_.size() > 0);
auto &cli = gc.liteclients_[0];
td::IPAddress addr;
addr.init_host_port(td::IPAddress::ipv4_to_str(cli->ip_), cli->port_).ensure();
client_ = ton::adnl::AdnlExtClient::create(ton::adnl::AdnlNodeIdFull::create(cli->id_).move_as_ok(), addr,
make_callback());
alarm_timestamp() = td::Timestamp::in(2.0);
}
};
td::Result<td::UInt256> get_uint256(std::string str) {
if (str.size() != 64) {
return td::Status::Error("uint256 must have 64 bytes");
}
td::UInt256 res;
for (size_t i = 0; i < 32; i++) {
res.raw[i] = static_cast<td::uint8>(td::hex_to_int(str[2 * i]) * 16 + td::hex_to_int(str[2 * i + 1]));
}
return res;
}
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_DEBUG);
td::set_default_failure_signal_handler().ensure();
td::actor::ActorOwn<TestNode> x;
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb(td::MutableSlice{b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('D', "db", "root for dbs", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_db_root, fname.str());
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
auto FileLog = td::FileFd::open(td::CSlice(fname.str().c_str()),
td::FileFd::Flags::Create | td::FileFd::Flags::Append | td::FileFd::Flags::Write)
.move_as_ok();
dup2(FileLog.get_native_fd().fd(), 1);
dup2(FileLog.get_native_fd().fd(), 2);
return td::Status::OK();
});
#endif
td::actor::Scheduler scheduler({2});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
scheduler.run();
return 0;
}

View file

@ -1,221 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU 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 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <iostream>
#include <sstream>
template <std::size_t size>
std::ostream &operator<<(std::ostream &stream, const td::UInt<size> &x) {
for (size_t i = 0; i < size / 8; i++) {
stream << td::format::hex_digit((x.raw[i] >> 4) & 15) << td::format::hex_digit(x.raw[i] & 15);
}
return stream;
}
class TestNode : public td::actor::Actor {
private:
td::actor::ActorOwn<ton::keyring::Keyring> keyring_;
td::actor::ActorOwn<ton::adnl::Adnl> adnl_;
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
std::unique_ptr<ton::adnl::Adnl::Callback> make_callback() {
class Callback : public ton::adnl::Adnl::Callback {
public:
void receive_message(ton::adnl::AdnlNodeIdShort src, ton::adnl::AdnlNodeIdShort dst,
td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::adnl_receive_message, src, dst, std::move(data));
}
void receive_query(ton::adnl::AdnlNodeIdShort src, ton::adnl::AdnlNodeIdShort dst, td::BufferSlice data,
td::Promise<td::BufferSlice> promise) override {
td::actor::send_closure(id_, &TestNode::adnl_receive_query, src, dst, std::move(data), std::move(promise));
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
std::string db_root_;
public:
void adnl_receive_message(ton::adnl::AdnlNodeIdShort src, ton::adnl::AdnlNodeIdShort dst, td::BufferSlice data) {
LOG(ERROR) << "ADNL MESSAGE FROM " << src << ": size=" << data.size() << "\n";
}
void adnl_receive_query(ton::adnl::AdnlNodeIdShort src, ton::adnl::AdnlNodeIdShort dst, td::BufferSlice data,
td::Promise<td::BufferSlice> promise) {
LOG(ERROR) << "ADNL QUERY FROM " << src << ": size=" << data.size() << "\n";
promise.set_value(ton::serialize_tl_object(ton::create_tl_object<ton::ton_api::testString>("xxx"), true));
}
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void set_db_root(std::string db_root) {
db_root_ = db_root;
}
void start_up() override {
}
void alarm() override {
}
TestNode() {
}
void run() {
keyring_ = ton::keyring::Keyring::create(db_root_ + "/keyring/");
adnl_ = ton::adnl::Adnl::create(db_root_, keyring_.get());
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
for (auto &port : lc.udp_ports_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_listening_udp_port, "0.0.0.0",
static_cast<td::uint16>(port));
}
//td::actor::send_closure(network_manager_, &ton::adnl::AdnlNetworkManager::load_local_config, std::move(lc.net_));
//td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ids_from_config, std::move(lc.local_ids_));
if (gc.adnl_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_static_nodes_from_config,
std::move(gc.adnl_->static_nodes_));
}
for (auto &x : lc.liteservers_) {
auto pk = ton::PrivateKey{x->id_};
auto pub_k = ton::adnl::AdnlNodeIdFull{pk.compute_public_key()};
auto id = pub_k.compute_short_id();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, pub_k, ton::adnl::AdnlAddressList{});
td::actor::send_closure(adnl_, &ton::adnl::Adnl::subscribe, id,
ton::adnl::Adnl::int_to_bytestring(ton::ton_api::getTestObject::ID), make_callback());
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ext_local_id, id);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ext_tcp_port, static_cast<td::uint16>(x->port_));
}
}
};
td::Result<td::UInt256> get_uint256(std::string str) {
if (str.size() != 64) {
return td::Status::Error("uint256 must have 64 bytes");
}
td::UInt256 res;
for (size_t i = 0; i < 32; i++) {
res.raw[i] = static_cast<td::uint8>(td::hex_to_int(str[2 * i]) * 16 + td::hex_to_int(str[2 * i + 1]));
}
return res;
}
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_DEBUG);
td::set_default_failure_signal_handler().ensure();
td::actor::ActorOwn<TestNode> x;
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb(td::MutableSlice{b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('D', "db", "root for dbs", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_db_root, fname.str());
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
auto FileLog = td::FileFd::open(td::CSlice(fname.str().c_str()),
td::FileFd::Flags::Create | td::FileFd::Flags::Append | td::FileFd::Flags::Write)
.move_as_ok();
dup2(FileLog.get_native_fd().fd(), 1);
dup2(FileLog.get_native_fd().fd(), 2);
return td::Status::OK();
});
#endif
td::actor::Scheduler scheduler({2});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
scheduler.run();
return 0;
}

View file

@ -1,376 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU 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 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#include "catchain/catchain.h"
#include "crypto/common/refvector.hpp"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <iostream>
#include <sstream>
template <std::size_t size>
std::ostream &operator<<(std::ostream &stream, const td::UInt<size> &x) {
for (size_t i = 0; i < size / 8; i++) {
stream << td::format::hex_digit((x.raw[i] >> 4) & 15) << td::format::hex_digit(x.raw[i] & 15);
}
return stream;
}
class TestNode : public td::actor::Actor {
private:
std::vector<td::UInt256> ping_ids_;
td::Timestamp next_dht_dump_;
td::actor::ActorOwn<ton::adnl::Adnl> adnl_;
std::vector<td::actor::ActorOwn<ton::dht::Dht>> dht_nodes_;
td::actor::ActorOwn<ton::overlay::Overlays> overlay_manager_;
std::vector<std::pair<td::UInt256, td::UInt256>> overlays_;
std::vector<td::actor::ActorOwn<ton::CatChain>> catchains_;
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
td::int32 broadcast_size_ = 100;
void receive_message(td::UInt256 src, td::UInt256 dst, td::BufferSlice data) {
LOG(ERROR) << "MESSAGE FROM " << src << " to " << dst << " of size " << std::to_string(data.size()) << "\n";
}
void receive_broadcast(td::UInt256 overlay_id, td::BufferSlice data) {
LOG(ERROR) << "BROADCAST IN " << overlay_id << " hash=" << td::sha256(data.as_slice()) << "\n";
}
void receive_query(td::UInt256 src, td::UInt256 dst, td::BufferSlice data, td::Promise<td::BufferSlice> promise) {
auto Q = ton::fetch_tl_object<ton::ton_api::getTestObject>(std::move(data), true);
CHECK(Q.is_ok());
auto R = Q.move_as_ok();
LOG(ERROR) << "QUERY "
<< " FROM " << src << " to " << dst << ": " << ton::ton_api::to_string(R) << "\n";
promise.set_value(serialize_tl_object(ton::create_tl_object<ton::ton_api::testObject>(), true));
}
void catchain_new_block(td::UInt256 src, td::uint64 height, td::BufferSlice data) {
LOG(ERROR) << "CATCHAIN BLOCK: " << src << "@" << height << ": " << td::sha256_uint256(data.as_slice()) << "\n";
}
void catchain_bad_block(td::UInt256 src) {
LOG(ERROR) << "CATCHAIN BAD BLOCK\n";
}
void catchain_broadcast(td::BufferSlice data) {
LOG(ERROR) << "CATCHAIN BROADCAST " << td::sha256_uint256(data.as_slice()) << "\n";
}
std::unique_ptr<ton::adnl::Adnl::Callback> make_callback() {
class Callback : public ton::adnl::Adnl::Callback {
public:
void receive_message(td::UInt256 src, td::UInt256 dst, td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::receive_message, src, dst, std::move(data));
}
void receive_query(td::UInt256 src, td::UInt256 dst, td::BufferSlice data,
td::Promise<td::BufferSlice> promise) override {
td::actor::send_closure(id_, &TestNode::receive_query, src, dst, std::move(data), std::move(promise));
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
std::unique_ptr<ton::CatChainActor::Callback> make_catchain_callback() {
class Callback : public ton::CatChainActor::Callback {
public:
void new_block(td::UInt256 src, td::uint64 height, td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::catchain_new_block, src, height, std::move(data));
}
void bad_block(td::UInt256 src) override {
td::actor::send_closure(id_, &TestNode::catchain_bad_block, src);
}
void broadcast(td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::catchain_broadcast, std::move(data));
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
std::unique_ptr<ton::overlay::Overlays::Callback> make_overlay_callback() {
class Callback : public ton::overlay::Overlays::Callback {
public:
void receive_message(td::UInt256 src, td::UInt256 overlay_id, td::BufferSlice data) override {
}
void receive_query(td::UInt256 src, td::uint64 query_id, td::UInt256 overlay_id, td::BufferSlice data) override {
}
void receive_broadcast(td::UInt256 overlay_id, td::BufferSlice data) override {
td::actor::send_closure(id_, &TestNode::receive_broadcast, overlay_id, std::move(data));
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
public:
void set_broadcast_size(td::int32 size) {
broadcast_size_ = size;
}
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void start_up() override {
alarm_timestamp() = td::Timestamp::in(1);
}
void alarm() override {
/*if (overlays_.size() > 0 && broadcast_size_ > 0) {
td::BufferSlice s(broadcast_size_);
td::Random::secure_bytes(s.as_slice());
td::actor::send_closure(overlay_manager_, &ton::overlay::OverlayManager::send_broadcast_fer, overlays_[0].first,
overlays_[0].second, ton::create_tl_object<ton::ton_api::testString>(s.as_slice().str()));
}*/
for (auto &chain : catchains_) {
td::BufferSlice s(broadcast_size_);
td::Random::secure_bytes(s.as_slice());
td::actor::send_closure(chain, &ton::CatChainActor::add_event, std::move(s));
}
alarm_timestamp() = td::Timestamp::in(1.0);
if (next_dht_dump_.is_in_past()) {
/*for (auto &node : dht_nodes_) {
char b[10240];
td::StringBuilder sb({b, 10000});
node->get_actor_unsafe().dump(sb);
LOG(DEBUG) << sb.as_cslice().c_str();
}*/
next_dht_dump_ = td::Timestamp::in(60.0);
}
}
TestNode() {
adnl_ = ton::adnl::Adnl::create("/var/ton-work/db.adnl");
}
void run() {
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
for (auto &port : lc.udp_ports_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_listening_udp_port, "0.0.0.0",
static_cast<td::uint16>(port));
}
/*if (!lc.net_) {
LOG(FATAL) << "local config does not contain NET section";
}*/
//td::actor::send_closure(network_manager_, &ton::adnl::AdnlNetworkManager::load_local_config, std::move(lc.net_));
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ids_from_config, std::move(lc.local_ids_));
if (gc.adnl_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_static_nodes_from_config,
std::move(gc.adnl_->static_nodes_));
}
if (!gc.dht_) {
LOG(FATAL) << "global config does not contain dht section";
}
for (auto &it : lc.dht_) {
if (it->get_id() == ton::ton_api::dht_config_local::ID) {
auto R = ton::dht::Dht::create_from_json(
ton::clone_tl_object(gc.dht_), ton::move_tl_object_as<ton::ton_api::dht_config_local>(it), adnl_.get());
if (R.is_error()) {
LOG(FATAL) << "fail creating dht node: " << R.move_as_error();
}
dht_nodes_.push_back(R.move_as_ok());
} else {
auto I = ton::move_tl_object_as<ton::ton_api::dht_config_random_local>(it);
for (int i = 0; i < I->cnt_; i++) {
auto R = ton::dht::Dht::create_random(ton::clone_tl_object(gc.dht_), ton::clone_tl_object(I->addr_list_),
adnl_.get());
if (R.is_error()) {
LOG(FATAL) << "fail creating dht node: " << R.move_as_error();
}
dht_nodes_.push_back(R.move_as_ok());
}
}
}
CHECK(dht_nodes_.size() > 0);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::register_dht_node, dht_nodes_[0].get());
//td::actor::send_closure(overlay_manager_, &ton::overlay::Overlays::register_dht_node, dht_nodes_[0].get());
overlay_manager_ = ton::overlay::Overlays::create(adnl_.get(), dht_nodes_[0].get());
for (auto &it : lc.public_overlays_) {
if (it->get_id() == ton::ton_api::overlay_config_local::ID) {
auto X = ton::move_tl_object_as<ton::ton_api::overlay_config_local>(it);
auto id = ton::create_tl_object<ton::ton_api::adnl_id_overlay>(X->name_.clone());
auto Id = ton::move_tl_object_as<ton::ton_api::adnl_id_Full>(id);
auto sid = ton::adnl_short_id(Id);
overlays_.emplace_back(X->id_->id_, sid);
td::actor::send_closure(overlay_manager_, &ton::overlay::Overlays::create_public_overlay, X->id_->id_,
std::move(Id), make_overlay_callback());
} else {
auto X = ton::move_tl_object_as<ton::ton_api::overlay_config_random_local>(it);
for (int i = 0; i < X->cnt_; i++) {
auto pk = ton::adnl_generate_random_pk();
auto local_id = ton::adnl_short_id(ton::get_public_key(pk));
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, std::move(pk), ton::clone_tl_object(X->addr_list_));
auto id = ton::create_tl_object<ton::ton_api::adnl_id_overlay>(X->name_.clone());
auto Id = ton::move_tl_object_as<ton::ton_api::adnl_id_Full>(id);
auto sid = ton::adnl_short_id(Id);
overlays_.emplace_back(local_id, sid);
td::actor::send_closure(overlay_manager_, &ton::overlay::Overlays::create_public_overlay, local_id,
std::move(Id), make_overlay_callback());
}
}
}
//auto C = ton::CatChainActor::create(nullptr, adnl_.get(), overlay_manager_.get(),
// std::vector<ton::tl_object_ptr<ton::ton_api::adnl_id_Full>>());
for (auto &it : lc.catchains_) {
auto tag = it->tag_;
for (auto &V : gc.catchains_) {
if (V->tag_ == tag) {
auto v = std::move(clone_tl_object(V)->nodes_);
auto C = ton::CatChainActor::create(make_catchain_callback(), adnl_.get(), overlay_manager_.get(),
std::move(v), it->id_->id_, tag);
catchains_.push_back(std::move(C));
}
}
}
}
};
td::Result<td::UInt256> get_uint256(std::string str) {
if (str.size() != 64) {
return td::Status::Error("uint256 must have 64 bytes");
}
td::UInt256 res;
for (size_t i = 0; i < 32; i++) {
res.raw[i] = static_cast<td::uint8>(td::hex_to_int(str[2 * i]) * 16 + td::hex_to_int(str[2 * i + 1]));
}
return res;
}
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_DEBUG);
td::set_default_failure_signal_handler().ensure();
td::actor::ActorOwn<TestNode> x;
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb({b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('s', "broadcast-size", "size of broadcast", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_broadcast_size, std::atoi(fname.str().c_str()));
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
auto FileLog = td::FileFd::open(td::CSlice(fname.str().c_str()),
td::FileFd::Flags::Create | td::FileFd::Flags::Append | td::FileFd::Flags::Write)
.move_as_ok();
dup2(FileLog.get_native_fd().fd(), 1);
dup2(FileLog.get_native_fd().fd(), 2);
return td::Status::OK();
});
#endif
td::actor::Scheduler scheduler({2});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
scheduler.run();
return 0;
}

View file

@ -40,7 +40,7 @@
int main() {
SET_VERBOSITY_LEVEL(verbosity_INFO);
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-rldp";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();

View file

@ -40,7 +40,7 @@
int main() {
SET_VERBOSITY_LEVEL(verbosity_INFO);
std::string db_root_ = "tmp-ee";
std::string db_root_ = "tmp-dir-test-rldp2";
td::rmrf(db_root_).ignore();
td::mkdir(db_root_).ensure();

View file

@ -50,7 +50,7 @@
#include "validator/fabric.h"
#include "validator/impl/collator.h"
#include "crypto/vm/cp0.h"
#include "crypto/vm/vm.h"
#include "crypto/block/block-db.h"
#include "common/errorlog.h"
@ -412,7 +412,7 @@ int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_INFO);
td::set_default_failure_signal_handler().ensure();
CHECK(vm::init_op_cp0());
vm::init_vm().ensure();
td::actor::ActorOwn<TestNode> x;

View file

@ -34,6 +34,7 @@
#include "validator-session/validator-session-description.h"
#include "validator-session/validator-session-state.h"
#include "validator-session/validator-session-description.hpp"
#include <limits>
#include <memory>
@ -48,16 +49,13 @@ class Description : public ton::validatorsession::ValidatorSessionDescription {
return 0;
}
void *alloc(size_t size, size_t align, bool temp) override {
td::uint32 idx = temp ? 1 : 0;
auto s = pdata_cur_[idx].fetch_add(size);
CHECK(s + size <= pdata_size_[idx]);
return static_cast<void *>(pdata_[idx] + s);
return (temp ? mem_temp_ : mem_perm_).alloc(size, align);
}
bool is_persistent(const void *ptr) const override {
return ptr == nullptr || (ptr >= pdata_[0] && ptr < pdata_[0] + pdata_size_[0]);
return mem_perm_.contains(ptr);
}
void clear_temp_memory() override {
pdata_cur_[1] = 0;
mem_temp_.clear();
}
ton::PublicKeyHash get_source_id(td::uint32 idx) const override {
@ -192,21 +190,8 @@ class Description : public ton::validatorsession::ValidatorSessionDescription {
return opts_;
}
~Description() {
delete[] pdata_[0];
delete[] pdata_[1];
}
Description(ton::validatorsession::ValidatorSessionOptions opts, td::uint32 total_nodes)
: opts_(opts), total_nodes_(total_nodes) {
pdata_size_[0] =
static_cast<std::size_t>(std::numeric_limits<std::size_t>::max() < (1ull << 32) ? 1ull << 30 : 1ull << 33);
pdata_size_[1] = 1 << 22;
pdata_[0] = new td::uint8[pdata_size_[0]];
pdata_[1] = new td::uint8[pdata_size_[1]];
pdata_cur_[0] = 0;
pdata_cur_[1] = 0;
: opts_(opts), total_nodes_(total_nodes), mem_perm_(1 << 30), mem_temp_(1 << 22) {
for (auto &el : cache_) {
Cached v{nullptr};
el.store(v, std::memory_order_relaxed);
@ -227,9 +212,7 @@ class Description : public ton::validatorsession::ValidatorSessionDescription {
};
std::array<std::atomic<Cached>, cache_size> cache_;
td::uint8 *pdata_[2];
std::atomic<size_t> pdata_cur_[2];
size_t pdata_size_[2];
ton::validatorsession::ValidatorSessionDescriptionImpl::MemPool mem_perm_, mem_temp_;
};
double myrand() {

View file

@ -1,356 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU 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 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "rldp/rldp.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#include "td/utils/overloaded.h"
#include "catchain/catchain.h"
#include "validator-session/validator-session.h"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <iostream>
#include <sstream>
class TestNode : public td::actor::Actor {
private:
td::actor::ActorOwn<ton::keyring::Keyring> keyring_;
td::actor::ActorOwn<ton::adnl::Adnl> adnl_;
td::actor::ActorOwn<ton::rldp::Rldp> rldp_;
std::vector<td::actor::ActorOwn<ton::dht::Dht>> dht_nodes_;
td::actor::ActorOwn<ton::overlay::Overlays> overlay_manager_;
std::vector<td::actor::ActorOwn<ton::validatorsession::ValidatorSession>> validator_sessions_;
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
std::unique_ptr<ton::validatorsession::ValidatorSession::Callback> make_vs_callback() {
class Callback : public ton::validatorsession::ValidatorSession::Callback {
public:
void on_candidate(td::uint32 round, ton::PublicKeyHash source,
ton::validatorsession::ValidatorSessionRootHash root_hash, td::BufferSlice data,
td::BufferSlice extra,
td::Promise<ton::validatorsession::ValidatorSession::CandidateDecision> promise) override {
td::actor::send_closure(id_, &TestNode::on_candidate, round, source, root_hash, std::move(data),
std::move(extra), std::move(promise));
}
void on_generate_slot(td::uint32 round, td::Promise<ton::BlockCandidate> promise) override {
td::actor::send_closure(id_, &TestNode::on_generate_slot, round, std::move(promise));
}
void on_block_committed(td::uint32 round, ton::PublicKeyHash src,
ton::validatorsession::ValidatorSessionRootHash root_hash,
ton::validatorsession::ValidatorSessionFileHash file_hash, td::BufferSlice data,
std::vector<std::pair<ton::PublicKeyHash, td::BufferSlice>> signatures,
ton::validatorsession::ValidatorSessionStats stats) override {
td::actor::send_closure(id_, &TestNode::on_block_committed, round, root_hash, std::move(data),
std::move(signatures));
}
/*void on_missing_block_committed(
td::uint32 round, ton::validatorsession::ValidatorSessionRootHash root_hash, ton::validatorsession::ValidatorSessionFileHash file_hash,
td::BufferSlice data, std::vector<std::pair<ton::adnl::AdnlNodeIdShort, td::BufferSlice>> signatures) override {
td::actor::send_closure(id_, &TestNode::on_block_committed_abscent, round, root_hash, file_hash,
std::move(data), std::move(signatures));
}*/
void on_block_skipped(td::uint32 round) override {
td::actor::send_closure(id_, &TestNode::on_block_skipped, round);
}
void get_approved_candidate(ton::validatorsession::ValidatorSessionRootHash root_hash,
ton::validatorsession::ValidatorSessionFileHash file_hash,
ton::validatorsession::ValidatorSessionFileHash collated_data_file_hash,
td::Promise<ton::BlockCandidate> promise) override {
UNREACHABLE();
}
Callback(td::actor::ActorId<TestNode> id) : id_(std::move(id)) {
}
private:
td::actor::ActorId<TestNode> id_;
};
return std::make_unique<Callback>(actor_id(this));
}
td::uint64 height_ = 0;
public:
void on_candidate(td::uint32 round, ton::PublicKeyHash source,
ton::validatorsession::ValidatorSessionRootHash root_hash, td::BufferSlice data,
td::BufferSlice collated,
td::Promise<ton::validatorsession::ValidatorSession::CandidateDecision> promise) {
auto sh = sha256_bits256(data.as_slice());
auto B = ton::fetch_tl_object<ton::ton_api::test_validatorSession_block>(std::move(data), true);
if (B.is_error()) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{B.move_as_error().to_string(), td::BufferSlice()});
return;
}
if (collated.size() != 32) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad collated data length", td::BufferSlice()});
return;
}
td::Bits256 x;
x.as_slice().copy_from(collated.as_slice().truncate(32));
if (x != sh) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad block hash", td::BufferSlice()});
return;
}
auto block = B.move_as_ok();
if (block->root_hash_ != root_hash) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad root hash", td::BufferSlice()});
return;
}
if (block->root_hash_ != sha256_bits256(block->data_.as_slice())) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad root hash (2)", td::BufferSlice()});
return;
}
if (block->height_ != static_cast<td::int64>(height_) + 1) {
promise.set_result(
ton::validatorsession::ValidatorSession::CandidateDecision{"bad root height", td::BufferSlice()});
return;
}
promise.set_result(ton::validatorsession::ValidatorSession::CandidateDecision{0});
}
void on_generate_slot(td::uint32 round, td::Promise<ton::BlockCandidate> promise) {
auto data = td::BufferSlice{10000};
td::Random::secure_bytes(data.as_slice());
auto root_hash = sha256_bits256(data.as_slice());
auto block =
ton::create_tl_object<ton::ton_api::test_validatorSession_block>(root_hash, height_ + 1, std::move(data));
auto B = ton::serialize_tl_object(block, true);
auto hash = sha256_bits256(B.as_slice());
auto collated = td::BufferSlice{32};
collated.as_slice().copy_from(as_slice(hash));
/*BlockId id;
BlockStatus status;
RootHash root_hash;
FileHash file_hash;
FileHash collated_file_hash;
td::BufferSlice data;
td::BufferSlice collated_data;*/
auto collated_file_hash = td::sha256_bits256(collated.as_slice());
ton::BlockCandidate candidate{ton::BlockIdExt{ton::BlockId{0, 0, 0}, root_hash, td::sha256_bits256(B.as_slice())},
collated_file_hash, std::move(B), std::move(collated)};
promise.set_result(std::move(candidate));
}
void on_block_committed(td::uint32 round, ton::validatorsession::ValidatorSessionRootHash root_hash,
td::BufferSlice data,
std::vector<std::pair<ton::PublicKeyHash, td::BufferSlice>> signatures) {
LOG(ERROR) << "COMITTED BLOCK: ROUND=" << round << " ROOT_HASH=" << root_hash
<< " DATA_HASH=" << sha256_bits256(data.as_slice()) << " SIGNED BY " << signatures.size();
}
void on_block_skipped(td::uint32 round) {
LOG(ERROR) << "SKIPPED ROUND=" << round;
}
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void start_up() override {
}
void alarm() override {
}
TestNode() {
}
void run() {
keyring_ = ton::keyring::Keyring::create("/var/ton-work/db.keyring");
adnl_ = ton::adnl::Adnl::create("/var/ton-work/db.adnl", keyring_.get());
rldp_ = ton::rldp::Rldp::create(adnl_.get());
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
for (auto &port : lc.udp_ports_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_listening_udp_port, "0.0.0.0",
static_cast<td::uint16>(port));
}
/*if (!lc.net_) {
LOG(FATAL) << "local config does not contain NET section";
}*/
//td::actor::send_closure(network_manager_, &ton::adnl::AdnlNetworkManager::load_local_config, std::move(lc.net_));
//td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ids_from_config, std::move(lc.local_ids_));
if (gc.adnl_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_static_nodes_from_config,
std::move(gc.adnl_->static_nodes_));
}
if (!gc.dht_) {
LOG(FATAL) << "global config does not contain dht section";
}
auto dhtR = ton::dht::Dht::create_global_config(std::move(gc.dht_));
if (dhtR.is_error()) {
LOG(FATAL) << "bad dht config: " << dhtR.move_as_error();
}
auto dht = dhtR.move_as_ok();
for (auto &it : lc.dht_) {
std::vector<ton::adnl::AdnlNodeIdShort> adnl_ids;
ton::ton_api::downcast_call(
*it.get(), td::overloaded(
[&](ton::ton_api::dht_config_local &obj) {
adnl_ids.push_back(ton::adnl::AdnlNodeIdShort{obj.id_->id_});
},
[&](ton::ton_api::dht_config_random_local &obj) {
auto addrR = ton::adnl::AdnlAddressList::create(std::move(obj.addr_list_));
addrR.ensure();
auto addr = addrR.move_as_ok();
for (td::int32 i = 0; i < obj.cnt_; i++) {
auto pk = ton::PrivateKey{ton::privkeys::Ed25519::random()};
auto pub = pk.compute_public_key();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, ton::adnl::AdnlNodeIdFull{pub},
addr);
auto adnl_id = ton::adnl::AdnlNodeIdShort{pub.compute_short_id()};
adnl_ids.push_back(adnl_id);
}
}));
for (auto &id : adnl_ids) {
auto R = ton::dht::Dht::create(id, "/var/ton-work/db/", dht, keyring_.get(), adnl_.get());
R.ensure();
dht_nodes_.push_back(R.move_as_ok());
}
}
CHECK(dht_nodes_.size() > 0);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::register_dht_node, dht_nodes_[0].get());
//td::actor::send_closure(overlay_manager_, &ton::overlay::Overlays::register_dht_node, dht_nodes_[0].get());
overlay_manager_ =
ton::overlay::Overlays::create("/var/ton-work/db.overlays", keyring_.get(), adnl_.get(), dht_nodes_[0].get());
//auto C = ton::CatChainActor::create(nullptr, adnl_.get(), overlay_manager_.get(),
// std::vector<ton::tl_object_ptr<ton::ton_api::adnl_id_Full>>());
for (auto &it : lc.catchains_) {
auto tag = it->tag_;
for (auto &V : gc.catchains_) {
if (V->tag_ == tag) {
auto v = std::move(clone_tl_object(V)->nodes_);
std::vector<ton::validatorsession::ValidatorSessionNode> w;
w.resize(v.size());
for (size_t i = 0; i < w.size(); i++) {
w[i].pub_key = ton::PublicKey{v[i]};
w[i].adnl_id = ton::adnl::AdnlNodeIdShort{w[i].pub_key.compute_short_id()};
w[i].weight = 1;
}
auto C = ton::validatorsession::ValidatorSession::create(
tag, ton::PublicKeyHash{it->id_->id_}, std::move(w), make_vs_callback(), keyring_.get(), adnl_.get(),
rldp_.get(), overlay_manager_.get(), "/var/ton-work/db/");
td::actor::send_closure(C, &ton::validatorsession::ValidatorSession::start);
validator_sessions_.emplace_back(std::move(C));
}
}
}
}
};
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_INFO);
td::set_default_failure_signal_handler().ensure();
td::actor::ActorOwn<TestNode> x;
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb(td::MutableSlice{b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
auto FileLog = td::FileFd::open(td::CSlice(fname.str().c_str()),
td::FileFd::Flags::Create | td::FileFd::Flags::Append | td::FileFd::Flags::Write)
.move_as_ok();
dup2(FileLog.get_native_fd().fd(), 1);
dup2(FileLog.get_native_fd().fd(), 2);
return td::Status::OK();
});
#endif
td::actor::Scheduler scheduler({7});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
scheduler.run();
return 0;
}

View file

@ -1,356 +0,0 @@
/*
This file is part of TON Blockchain source code.
TON Blockchain is free software; you can redistribute it and/or
modify it under the terms of the GNU 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 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with TON Blockchain. If not, see <http://www.gnu.org/licenses/>.
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library.
You must obey the GNU General Public License in all respects for all
of the code used other than OpenSSL. If you modify file(s) with this
exception, you may extend this exception to your version of the file(s),
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl/adnl.h"
#include "rldp/rldp.h"
#include "adnl/utils.hpp"
#include "auto/tl/ton_api_json.h"
#include "auto/tl/ton_api.hpp"
#include "dht/dht.h"
#include "overlay/overlays.h"
#include "td/utils/OptionParser.h"
#include "td/utils/Time.h"
#include "td/utils/TsFileLog.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/Random.h"
#include "td/utils/port/signals.h"
#include "td/utils/port/FileFd.h"
#include "catchain/catchain.h"
#include "validator-session/validator-session.h"
#include "ton-node/ton-node.h"
#include "validator/manager.h"
#include "td/utils/filesystem.h"
#include "td/utils/ThreadSafeCounter.h"
#include "td/utils/port/path.h"
#include "crypto/vm/cp0.h"
#include "td/utils/overloaded.h"
#include "memprof/memprof.h"
#if TD_DARWIN || TD_LINUX
#include <unistd.h>
#endif
#include <algorithm>
#include <iostream>
#include <sstream>
class TestNode : public td::actor::Actor {
private:
td::actor::ActorOwn<ton::keyring::Keyring> keyring_;
td::actor::ActorOwn<ton::adnl::Adnl> adnl_;
td::actor::ActorOwn<ton::rldp::Rldp> rldp_;
std::vector<td::actor::ActorOwn<ton::dht::Dht>> dht_nodes_;
td::actor::ActorOwn<ton::overlay::Overlays> overlay_manager_;
td::actor::ActorOwn<ton::ValidatorManager> validator_manager_;
td::actor::ActorOwn<ton::TonNodeManager> ton_node_;
std::string local_config_ = "ton-local.config";
std::string global_config_ = "ton-global.config";
std::string db_root_ = "/var/ton-work/db/";
std::string zero_state_ = "";
public:
void set_local_config(std::string str) {
local_config_ = str;
}
void set_global_config(std::string str) {
global_config_ = str;
}
void set_db_root(std::string db_root) {
db_root_ = db_root;
}
void set_zero_state(std::string zero_state) {
zero_state_ = zero_state;
}
void start_up() override {
}
void alarm() override {
}
TestNode() {
}
void run() {
td::mkdir(db_root_).ensure();
keyring_ = ton::keyring::Keyring::create(db_root_ + "/keyring");
adnl_ = ton::adnl::Adnl::create(db_root_, keyring_.get());
rldp_ = ton::rldp::Rldp::create(adnl_.get());
auto L = td::read_file(local_config_).move_as_ok();
auto lc_j = td::json_decode(L.as_slice()).move_as_ok();
ton::ton_api::config_local lc;
ton::ton_api::from_json(lc, lc_j.get_object()).ensure();
auto G = td::read_file(global_config_).move_as_ok();
auto gc_j = td::json_decode(G.as_slice()).move_as_ok();
ton::ton_api::config_global gc;
ton::ton_api::from_json(gc, gc_j.get_object()).ensure();
for (auto &port : lc.udp_ports_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_listening_udp_port, "0.0.0.0",
static_cast<td::uint16>(port));
}
/*if (!lc.net_) {
LOG(FATAL) << "local config does not contain NET section";
}*/
//td::actor::send_closure(network_manager_, &ton::adnl::AdnlNetworkManager::load_local_config, std::move(lc.net_));
//td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_ids_from_config, std::move(lc.local_ids_));
for (auto &local_id : lc.local_ids_) {
auto pk = ton::PrivateKey{local_id->id_};
auto pub = pk.compute_public_key();
auto addr_list = ton::adnl::AdnlAddressList::create(local_id->addr_list_);
addr_list.ensure();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, ton::adnl::AdnlNodeIdFull{pub}, addr_list.move_as_ok());
}
if (gc.adnl_) {
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_static_nodes_from_config,
std::move(gc.adnl_->static_nodes_));
}
if (!gc.dht_) {
LOG(FATAL) << "global config does not contain dht section";
}
auto dhtR = ton::dht::Dht::create_global_config(std::move(gc.dht_));
if (dhtR.is_error()) {
LOG(FATAL) << "bad dht config: " << dhtR.move_as_error();
}
auto dht = dhtR.move_as_ok();
for (auto &it : lc.dht_) {
std::vector<ton::adnl::AdnlNodeIdShort> adnl_ids;
ton::ton_api::downcast_call(
*it.get(), td::overloaded(
[&](ton::ton_api::dht_config_local &obj) {
adnl_ids.push_back(ton::adnl::AdnlNodeIdShort{obj.id_->id_});
},
[&](ton::ton_api::dht_config_random_local &obj) {
auto addrR = ton::adnl::AdnlAddressList::create(std::move(obj.addr_list_));
addrR.ensure();
auto addr = addrR.move_as_ok();
for (td::int32 i = 0; i < obj.cnt_; i++) {
auto pk = ton::PrivateKey{ton::privkeys::Ed25519::random()};
auto pub = pk.compute_public_key();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, ton::adnl::AdnlNodeIdFull{pub},
addr);
auto adnl_id = ton::adnl::AdnlNodeIdShort{pub.compute_short_id()};
adnl_ids.push_back(adnl_id);
}
}));
for (auto &id : adnl_ids) {
auto R = ton::dht::Dht::create(id, db_root_, dht, keyring_.get(), adnl_.get());
R.ensure();
dht_nodes_.push_back(R.move_as_ok());
}
}
CHECK(dht_nodes_.size() > 0);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::register_dht_node, dht_nodes_[0].get());
overlay_manager_ = ton::overlay::Overlays::create(db_root_, keyring_.get(), adnl_.get(), dht_nodes_[0].get());
CHECK(lc.validators_.size() <= 1);
CHECK(gc.validators_.size() <= 1);
bool is_validator = false;
if (lc.validators_.size() == 1) {
CHECK(gc.validators_.size() == 1);
auto zero_state_id =
ton::BlockIdExt{ton::masterchainId, ton::shardIdAll, 0, gc.validators_[0]->zero_state_root_hash_,
gc.validators_[0]->zero_state_file_hash_};
ton::PublicKeyHash id;
ton::adnl::AdnlNodeIdShort adnl_id;
ton::ton_api::downcast_call(*lc.validators_[0].get(),
td::overloaded(
[&](ton::ton_api::validator_config_local &cfg) {
id = ton::PublicKeyHash{cfg.id_->id_};
adnl_id = ton::adnl::AdnlNodeIdShort{id};
is_validator = true;
},
[&](ton::ton_api::validator_config_random_local &cfg) {
auto privkey = ton::PrivateKey{ton::privkeys::Ed25519::random()};
auto pubkey = ton::adnl::AdnlNodeIdFull{privkey.compute_public_key()};
auto addrR = ton::adnl::AdnlAddressList::create(std::move(cfg.addr_list_));
addrR.ensure();
auto addr = addrR.move_as_ok();
id = privkey.compute_short_id();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key,
std::move(privkey), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, pubkey, addr);
adnl_id = ton::adnl::AdnlNodeIdShort{id};
}));
auto opts = ton::ValidatorManagerOptions::create(
zero_state_id, std::vector<ton::ShardIdFull>{ton::ShardIdFull{ton::basechainId, ton::shardIdAll}});
CHECK(!opts.is_null());
opts.write().set_allow_blockchain_init(is_validator);
validator_manager_ =
ton::ValidatorManagerFactory::create(is_validator ? id : ton::PublicKeyHash::zero(), opts, db_root_,
keyring_.get(), adnl_.get(), rldp_.get(), overlay_manager_.get());
ton_node_ =
ton::TonNodeManager::create(adnl_id, gc.validators_[0]->zero_state_file_hash_, adnl_.get(), rldp_.get(),
dht_nodes_[0].get(), overlay_manager_.get(), validator_manager_.get(), db_root_);
for (auto &x : lc.liteservers_) {
auto pk = ton::PrivateKey{x->id_};
auto pub_k = ton::adnl::AdnlNodeIdFull{pk.compute_public_key()};
auto id = pub_k.compute_short_id();
td::actor::send_closure(keyring_, &ton::keyring::Keyring::add_key, std::move(pk), false);
td::actor::send_closure(adnl_, &ton::adnl::Adnl::add_id, pub_k, ton::adnl::AdnlAddressList{});
td::actor::send_closure(validator_manager_, &ton::ValidatorManager::add_ext_server_id, id);
td::actor::send_closure(validator_manager_, &ton::ValidatorManager::add_ext_server_port,
static_cast<td::uint16>(x->port_));
}
}
}
};
td::Result<td::UInt256> get_uint256(std::string str) {
if (str.size() != 64) {
return td::Status::Error("uint256 must have 64 bytes");
}
td::UInt256 res;
for (size_t i = 0; i < 32; i++) {
res.raw[i] = static_cast<td::uint8>(td::hex_to_int(str[2 * i]) * 16 + td::hex_to_int(str[2 * i + 1]));
}
return res;
}
std::atomic<bool> need_stats_flag{false};
void need_stats(int sig) {
need_stats_flag.store(true);
}
void dump_memory_stats() {
if (!is_memprof_on()) {
return;
}
LOG(WARNING) << "memory_dump";
std::vector<AllocInfo> v;
dump_alloc([&](const AllocInfo &info) { v.push_back(info); });
std::sort(v.begin(), v.end(), [](const AllocInfo &a, const AllocInfo &b) { return a.size > b.size; });
size_t total_size = 0;
size_t other_size = 0;
int cnt = 0;
for (auto &info : v) {
if (cnt++ < 50) {
LOG(WARNING) << td::format::as_size(info.size) << td::format::as_array(info.backtrace);
} else {
other_size += info.size;
}
total_size += info.size;
}
LOG(WARNING) << td::tag("other", td::format::as_size(other_size));
LOG(WARNING) << td::tag("total", td::format::as_size(total_size));
LOG(WARNING) << td::tag("total traces", get_ht_size());
LOG(WARNING) << td::tag("fast_backtrace_success_rate", get_fast_backtrace_success_rate());
}
void dump_stats() {
dump_memory_stats();
LOG(WARNING) << td::NamedThreadSafeCounter::get_default();
}
int main(int argc, char *argv[]) {
SET_VERBOSITY_LEVEL(verbosity_INFO);
td::set_default_failure_signal_handler().ensure();
CHECK(vm::init_op_cp0());
td::actor::ActorOwn<TestNode> x;
td::unique_ptr<td::LogInterface> logger_;
SCOPE_EXIT {
td::log_interface = td::default_log_interface;
};
td::OptionParser p;
p.set_description("test basic adnl functionality");
p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) {
int v = VERBOSITY_NAME(FATAL) + (td::to_integer<int>(arg));
SET_VERBOSITY_LEVEL(v);
return td::Status::OK();
});
p.add_option('h', "help", "prints_help", [&]() {
char b[10240];
td::StringBuilder sb(td::MutableSlice{b, 10000});
sb << p;
std::cout << sb.as_cslice().c_str();
std::exit(2);
return td::Status::OK();
});
p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_global_config, fname.str());
return td::Status::OK();
});
p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_local_config, fname.str());
return td::Status::OK();
});
p.add_option('i', "id", "id of instance", [&](td::Slice fname) { return td::Status::OK(); });
p.add_option('D', "db", "root for dbs", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_db_root, fname.str());
return td::Status::OK();
});
p.add_option('z', "zero-state", "file with serialized zero state", [&](td::Slice fname) {
td::actor::send_closure(x, &TestNode::set_zero_state, fname.str());
return td::Status::OK();
});
p.add_option('d', "daemonize", "set SIGHUP", [&]() {
td::set_signal_handler(td::SignalType::HangUp, [](int sig) {
#if TD_DARWIN || TD_LINUX
close(0);
setsid();
#endif
}).ensure();
return td::Status::OK();
});
#if TD_DARWIN || TD_LINUX
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
logger_ = td::TsFileLog::create(fname.str()).move_as_ok();
td::log_interface = logger_.get();
return td::Status::OK();
});
#endif
td::set_runtime_signal_handler(1, need_stats).ensure();
td::actor::Scheduler scheduler({7});
scheduler.run_in_context([&] { x = td::actor::create_actor<TestNode>("testnode"); });
scheduler.run_in_context([&] { p.run(argc, argv).ensure(); });
scheduler.run_in_context([&] { td::actor::send_closure(x, &TestNode::run); });
while (scheduler.run(1)) {
if (need_stats_flag.exchange(false)) {
dump_stats();
}
}
return 0;
}