43
43
#include " td/utils/filesystem.h"
44
44
#include " td/utils/port/path.h"
45
45
46
+ #include " ton/ton-types.h"
47
+ #include " ton/ton-tl.hpp"
48
+ #include " ton/ton-io.hpp"
49
+
50
+
46
51
#include " validator/fabric.h"
47
52
#include " validator/impl/collator.h"
48
53
#include " crypto/vm/cp0.h"
@@ -76,6 +81,9 @@ class TestNode : public td::actor::Actor {
76
81
td::actor::ActorOwn<ton::validator::ValidatorManagerInterface> validator_manager_;
77
82
78
83
std::string db_root_ = " /var/ton-work/db/" ;
84
+ std::string global_config_;
85
+ td::Ref<ton::validator::ValidatorManagerOptions> opts_;
86
+
79
87
ton::ZeroStateIdExt zero_id_;
80
88
td::BufferSlice bs_;
81
89
std::vector<td::BufferSlice> ext_msgs_;
@@ -92,6 +100,10 @@ class TestNode : public td::actor::Actor {
92
100
void set_db_root (std::string db_root) {
93
101
db_root_ = db_root;
94
102
}
103
+ void set_global_config_path (std::string path) {
104
+ global_config_ = path;
105
+ }
106
+
95
107
void set_zero_root_hash (td::Bits256 hash) {
96
108
zero_id_.root_hash = hash;
97
109
}
@@ -218,6 +230,54 @@ class TestNode : public td::actor::Actor {
218
230
}
219
231
}
220
232
233
+ td::Status create_validator_options () {
234
+ if (!global_config_.length ()) {
235
+ LOG (INFO) << " no global config file passed. Using zero-init config" ;
236
+ opts_ = ton::validator::ValidatorManagerOptions::create (
237
+ ton::BlockIdExt{ton::masterchainId, ton::shardIdAll, 0 , ton::RootHash::zero (), ton::FileHash::zero ()},
238
+ ton::BlockIdExt{ton::masterchainId, ton::shardIdAll, 0 , ton::RootHash::zero (), ton::FileHash::zero ()});
239
+ return td::Status::OK ();
240
+ }
241
+ TRY_RESULT_PREFIX (conf_data, td::read_file (global_config_), " failed to read: " );
242
+ TRY_RESULT_PREFIX (conf_json, td::json_decode (conf_data.as_slice ()), " failed to parse json: " );
243
+
244
+ ton::ton_api::config_global conf;
245
+ TRY_STATUS_PREFIX (ton::ton_api::from_json (conf, conf_json.get_object ()), " json does not fit TL scheme: " );
246
+
247
+ auto zero_state = ton::create_block_id (conf.validator_ ->zero_state_ );
248
+ ton::BlockIdExt init_block;
249
+ if (!conf.validator_ ->init_block_ ) {
250
+ LOG (INFO) << " no init block in config. using zero state" ;
251
+ init_block = zero_state;
252
+ } else {
253
+ init_block = ton::create_block_id (conf.validator_ ->init_block_ );
254
+ }
255
+ opts_ = ton::validator::ValidatorManagerOptions::create (zero_state, init_block);
256
+ std::vector<ton::BlockIdExt> h;
257
+ for (auto &x : conf.validator_ ->hardforks_ ) {
258
+ auto b = ton::create_block_id (x);
259
+ if (!b.is_masterchain ()) {
260
+ return td::Status::Error (ton::ErrorCode::error,
261
+ " [validator/hardforks] section contains not masterchain block id" );
262
+ }
263
+ if (!b.is_valid_full ()) {
264
+ return td::Status::Error (ton::ErrorCode::error, " [validator/hardforks] section contains invalid block_id" );
265
+ }
266
+ for (auto &y : h) {
267
+ if (y.is_valid () && y.seqno () >= b.seqno ()) {
268
+ y.invalidate ();
269
+ }
270
+ }
271
+ h.push_back (b);
272
+ }
273
+ opts_.write ().set_hardforks (std::move (h));
274
+
275
+
276
+ LOG (INFO) << " Hardforks num in config: " << opts_->get_hardforks ().size ();
277
+ return td::Status::OK ();
278
+ }
279
+
280
+
221
281
void run () {
222
282
zero_id_.workchain = ton::masterchainId;
223
283
td::mkdir (db_root_).ensure ();
@@ -227,9 +287,14 @@ class TestNode : public td::actor::Actor {
227
287
do_save_file ();
228
288
}
229
289
230
- auto opts = ton::validator::ValidatorManagerOptions::create (
231
- ton::BlockIdExt{ton::masterchainId, ton::shardIdAll, 0 , zero_id_.root_hash , zero_id_.file_hash },
232
- ton::BlockIdExt{ton::masterchainId, ton::shardIdAll, 0 , zero_id_.root_hash , zero_id_.file_hash });
290
+ auto Sr = create_validator_options ();
291
+ if (Sr.is_error ()) {
292
+ LOG (ERROR) << " failed to load global config'" << global_config_ << " ': " << Sr;
293
+ std::_Exit (2 );
294
+ }
295
+
296
+ auto opts = opts_;
297
+
233
298
opts.write ().set_initial_sync_disabled (true );
234
299
validator_manager_ = ton::validator::ValidatorManagerDiskFactory::create (ton::PublicKeyHash::zero (), opts, shard_,
235
300
shard_top_block_id_, db_root_);
@@ -366,6 +431,8 @@ int main(int argc, char *argv[]) {
366
431
[&](td::Slice fname) { td::actor::send_closure (x, &TestNode::set_zero_file, fname.str ()); });
367
432
p.add_option (' D' , " db" , " root for dbs" ,
368
433
[&](td::Slice fname) { td::actor::send_closure (x, &TestNode::set_db_root, fname.str ()); });
434
+ p.add_option (' C' , " config" , " global config path" ,
435
+ [&](td::Slice fname) { td::actor::send_closure (x, &TestNode::set_global_config_path, fname.str ()); });
369
436
p.add_option (' m' , " ext-message" , " binary file with serialized inbound external message" ,
370
437
[&](td::Slice fname) { td::actor::send_closure (x, &TestNode::load_ext_message, fname.str ()); });
371
438
p.add_option (' M' , " top-shard-message" , " binary file with serialized shard top block description" ,
0 commit comments