forked from ton-blockchain/ton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidator-options.hpp
300 lines (286 loc) · 9.87 KB
/
validator-options.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*
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
*/
#pragma once
#include "validator/validator.h"
namespace ton {
namespace validator {
struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
public:
BlockIdExt zero_block_id() const override {
return zero_block_id_;
}
BlockIdExt init_block_id() const override {
return init_block_id_;
}
bool need_monitor(ShardIdFull shard) const override {
return check_shard_(shard, 0, ShardCheckMode::m_monitor);
}
bool need_validate(ShardIdFull shard, CatchainSeqno cc_seqno) const override {
return check_shard_(shard, cc_seqno, ShardCheckMode::m_validate);
}
bool allow_blockchain_init() const override {
return allow_blockchain_init_;
}
double sync_blocks_before() const override {
return sync_blocks_before_;
}
double block_ttl() const override {
return block_ttl_;
}
double state_ttl() const override {
return state_ttl_;
}
double max_mempool_num() const override {
return max_mempool_num_;
}
double archive_ttl() const override {
return archive_ttl_;
}
double key_proof_ttl() const override {
return key_proof_ttl_;
}
bool initial_sync_disabled() const override {
return initial_sync_disabled_;
}
bool is_hardfork(BlockIdExt block_id) const override {
if (!block_id.is_valid()) {
return false;
}
for (size_t i = 0; i < hardforks_.size(); i++) {
if (block_id == hardforks_[i]) {
return (i == hardforks_.size() - 1) || block_id.seqno() < hardforks_[i + 1].seqno();
}
}
return false;
}
td::uint32 get_vertical_seqno(BlockSeqno seqno) const override {
size_t best = 0;
for (size_t i = 0; i < hardforks_.size(); i++) {
if (seqno >= hardforks_[i].seqno()) {
best = i + 1;
}
}
return static_cast<td::uint32>(best);
}
td::uint32 get_maximal_vertical_seqno() const override {
return td::narrow_cast<td::uint32>(hardforks_.size());
}
td::uint32 get_last_fork_masterchain_seqno() const override {
return hardforks_.size() ? hardforks_.rbegin()->seqno() : 0;
}
std::vector<BlockIdExt> get_hardforks() const override {
return hardforks_;
}
bool check_unsafe_resync_allowed(CatchainSeqno seqno) const override {
return unsafe_catchains_.count(seqno) > 0;
}
td::uint32 check_unsafe_catchain_rotate(BlockSeqno seqno, CatchainSeqno cc_seqno) const override {
auto it = unsafe_catchain_rotates_.find(cc_seqno);
if (it == unsafe_catchain_rotates_.end()) {
return 0;
} else {
return it->second.first <= seqno ? it->second.second : 0;
}
}
bool need_db_truncate() const override {
return truncate_ > 0;
}
BlockSeqno get_truncate_seqno() const override {
return truncate_;
}
BlockSeqno sync_upto() const override {
return sync_upto_;
}
std::string get_session_logs_file() const override {
return session_logs_file_;
}
td::uint32 get_celldb_compress_depth() const override {
return celldb_compress_depth_;
}
size_t get_max_open_archive_files() const override {
return max_open_archive_files_;
}
double get_archive_preload_period() const override {
return archive_preload_period_;
}
bool get_disable_rocksdb_stats() const override {
return disable_rocksdb_stats_;
}
bool nonfinal_ls_queries_enabled() const override {
return nonfinal_ls_queries_enabled_;
}
td::optional<td::uint64> get_celldb_cache_size() const override {
return celldb_cache_size_;
}
bool get_celldb_direct_io() const override {
return celldb_direct_io_;
}
bool get_celldb_preload_all() const override {
return celldb_preload_all_;
}
td::optional<double> get_catchain_max_block_delay() const override {
return catchain_max_block_delay_;
}
bool get_state_serializer_enabled() const override {
return state_serializer_enabled_;
}
td::Ref<CollatorOptions> get_collator_options() const override {
return collator_options_;
}
bool get_fast_state_serializer_enabled() const override {
return fast_state_serializer_enabled_;
}
void set_zero_block_id(BlockIdExt block_id) override {
zero_block_id_ = block_id;
}
void set_init_block_id(BlockIdExt block_id) override {
init_block_id_ = block_id;
}
void set_shard_check_function(std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard) override {
check_shard_ = std::move(check_shard);
}
void set_allow_blockchain_init(bool value) override {
allow_blockchain_init_ = value;
}
void set_sync_blocks_before(double value) override {
sync_blocks_before_ = value;
}
void set_block_ttl(double value) override {
block_ttl_ = value;
}
void set_state_ttl(double value) override {
state_ttl_ = value;
}
void set_max_mempool_num(double value) override {
max_mempool_num_ = value;
}
void set_archive_ttl(double value) override {
archive_ttl_ = value;
}
void set_key_proof_ttl(double value) override {
key_proof_ttl_ = value;
}
void set_initial_sync_disabled(bool value) override {
initial_sync_disabled_ = value;
}
void set_hardforks(std::vector<BlockIdExt> vec) override {
hardforks_ = std::move(vec);
}
void add_unsafe_resync_catchain(CatchainSeqno seqno) override {
unsafe_catchains_.insert(seqno);
}
void add_unsafe_catchain_rotate(BlockSeqno seqno, CatchainSeqno cc_seqno, td::uint32 value) override {
VLOG(INFO) << "Add unsafe catchain rotation: Master block seqno " << seqno<<" Catchain seqno " << cc_seqno << " New value "<< value;
unsafe_catchain_rotates_[cc_seqno] = std::make_pair(seqno, value);
}
void truncate_db(BlockSeqno seqno) override {
truncate_ = seqno;
}
void set_sync_upto(BlockSeqno seqno) override {
sync_upto_ = seqno;
}
void set_session_logs_file(std::string f) override {
session_logs_file_ = std::move(f);
}
void set_celldb_compress_depth(td::uint32 value) override {
celldb_compress_depth_ = value;
}
void set_max_open_archive_files(size_t value) override {
max_open_archive_files_ = value;
}
void set_archive_preload_period(double value) override {
archive_preload_period_ = value;
}
void set_disable_rocksdb_stats(bool value) override {
disable_rocksdb_stats_ = value;
}
void set_nonfinal_ls_queries_enabled(bool value) override {
nonfinal_ls_queries_enabled_ = value;
}
void set_celldb_cache_size(td::uint64 value) override {
celldb_cache_size_ = value;
}
void set_celldb_direct_io(bool value) override {
celldb_direct_io_ = value;
}
void set_celldb_preload_all(bool value) override {
celldb_preload_all_ = value;
}
void set_catchain_max_block_delay(double value) override {
catchain_max_block_delay_ = value;
}
void set_state_serializer_enabled(bool value) override {
state_serializer_enabled_ = value;
}
void set_collator_options(td::Ref<CollatorOptions> value) override {
collator_options_ = std::move(value);
}
void set_fast_state_serializer_enabled(bool value) override {
fast_state_serializer_enabled_ = value;
}
ValidatorManagerOptionsImpl *make_copy() const override {
return new ValidatorManagerOptionsImpl(*this);
}
ValidatorManagerOptionsImpl(BlockIdExt zero_block_id, BlockIdExt init_block_id,
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard,
bool allow_blockchain_init, double sync_blocks_before,
double block_ttl, double state_ttl, double max_mempool_num,
double archive_ttl, double key_proof_ttl,
bool initial_sync_disabled)
: zero_block_id_(zero_block_id)
, init_block_id_(init_block_id)
, check_shard_(std::move(check_shard))
, allow_blockchain_init_(allow_blockchain_init)
, sync_blocks_before_(sync_blocks_before)
, block_ttl_(block_ttl)
, state_ttl_(state_ttl)
, max_mempool_num_(max_mempool_num)
, archive_ttl_(archive_ttl)
, key_proof_ttl_(key_proof_ttl)
, initial_sync_disabled_(initial_sync_disabled) {
}
private:
BlockIdExt zero_block_id_;
BlockIdExt init_block_id_;
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard_;
bool allow_blockchain_init_;
double sync_blocks_before_;
double block_ttl_;
double state_ttl_;
double max_mempool_num_;
double archive_ttl_;
double key_proof_ttl_;
bool initial_sync_disabled_;
std::vector<BlockIdExt> hardforks_;
std::set<CatchainSeqno> unsafe_catchains_;
std::map<CatchainSeqno, std::pair<BlockSeqno, td::uint32>> unsafe_catchain_rotates_;
BlockSeqno truncate_{0};
BlockSeqno sync_upto_{0};
std::string session_logs_file_;
td::uint32 celldb_compress_depth_{0};
size_t max_open_archive_files_ = 0;
double archive_preload_period_ = 0.0;
bool disable_rocksdb_stats_;
bool nonfinal_ls_queries_enabled_ = false;
td::optional<td::uint64> celldb_cache_size_;
bool celldb_direct_io_ = false;
bool celldb_preload_all_ = false;
td::optional<double> catchain_max_block_delay_;
bool state_serializer_enabled_ = true;
td::Ref<CollatorOptions> collator_options_{true};
bool fast_state_serializer_enabled_ = false;
};
} // namespace validator
} // namespace ton