Skip to content

Commit 959be8f

Browse files
committed
Fix serializing candidate broadcast; allow collating before receiving all collated data; cleanup code
1 parent c07bffa commit 959be8f

14 files changed

+126
-84
lines changed

validator-session/candidate-serializer.cpp

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,38 @@ td::Result<td::BufferSlice> serialize_candidate(const tl_object_ptr<ton_api::val
3636

3737
td::Result<tl_object_ptr<ton_api::validatorSession_candidate>> deserialize_candidate(td::Slice data,
3838
bool compression_enabled,
39-
int max_decompressed_data_size,
40-
int proto_version) {
39+
int max_decompressed_data_size) {
4140
if (!compression_enabled) {
4241
return fetch_tl_object<ton_api::validatorSession_candidate>(data, true);
4342
}
4443
TRY_RESULT(f, fetch_tl_object<ton_api::validatorSession_Candidate>(data, true));
4544
td::Result<tl_object_ptr<ton_api::validatorSession_candidate>> res;
46-
ton_api::downcast_call(*f, td::overloaded(
47-
[&](ton_api::validatorSession_candidate& c) {
48-
res = td::Status::Error("Received decompressed tl object, while compression_enabled=true");
49-
},
50-
[&](ton_api::validatorSession_compressedCandidate& c) {
51-
res = [&]() -> td::Result<tl_object_ptr<ton_api::validatorSession_candidate>> {
52-
if (c.decompressed_size_ > max_decompressed_data_size) {
53-
return td::Status::Error("decompressed size is too big");
54-
}
55-
TRY_RESULT(p, decompress_candidate_data(c.data_, false, c.decompressed_size_,
56-
max_decompressed_data_size, proto_version));
57-
return create_tl_object<ton_api::validatorSession_candidate>(c.src_, c.round_, c.root_hash_, std::move(p.first),
58-
std::move(p.second));
59-
}();
60-
},
61-
[&](ton_api::validatorSession_compressedCandidateV2& c) {
62-
res = [&]() -> td::Result<tl_object_ptr<ton_api::validatorSession_candidate>> {
63-
if (c.data_.size() > max_decompressed_data_size) {
64-
return td::Status::Error("Compressed data is too big");
65-
}
66-
TRY_RESULT(p, decompress_candidate_data(c.data_, true, 0,
67-
max_decompressed_data_size, proto_version));
68-
return create_tl_object<ton_api::validatorSession_candidate>(c.src_, c.round_, c.root_hash_, std::move(p.first),
69-
std::move(p.second));
70-
}();
71-
}));
45+
ton_api::downcast_call(
46+
*f, td::overloaded(
47+
[&](ton_api::validatorSession_candidate& c) {
48+
res = td::Status::Error("Received decompressed tl object, while compression_enabled=true");
49+
},
50+
[&](ton_api::validatorSession_compressedCandidate& c) {
51+
res = [&]() -> td::Result<tl_object_ptr<ton_api::validatorSession_candidate>> {
52+
if (c.decompressed_size_ > max_decompressed_data_size) {
53+
return td::Status::Error("decompressed size is too big");
54+
}
55+
TRY_RESULT(
56+
p, decompress_candidate_data(c.data_, false, c.decompressed_size_, max_decompressed_data_size));
57+
return create_tl_object<ton_api::validatorSession_candidate>(c.src_, c.round_, c.root_hash_,
58+
std::move(p.first), std::move(p.second));
59+
}();
60+
},
61+
[&](ton_api::validatorSession_compressedCandidateV2& c) {
62+
res = [&]() -> td::Result<tl_object_ptr<ton_api::validatorSession_candidate>> {
63+
if (c.data_.size() > max_decompressed_data_size) {
64+
return td::Status::Error("Compressed data is too big");
65+
}
66+
TRY_RESULT(p, decompress_candidate_data(c.data_, true, 0, max_decompressed_data_size));
67+
return create_tl_object<ton_api::validatorSession_candidate>(c.src_, c.round_, c.root_hash_,
68+
std::move(p.first), std::move(p.second));
69+
}();
70+
}));
7271
return res;
7372
}
7473

@@ -80,7 +79,7 @@ td::Result<td::BufferSlice> compress_candidate_data(td::Slice block, td::Slice c
8079
return td::Status::Error("block candidate should have exactly one root");
8180
}
8281
std::vector<td::Ref<vm::Cell>> roots = {boc1.get_root_cell()};
83-
TRY_STATUS(boc2.deserialize(collated_data));
82+
TRY_STATUS(boc2.deserialize(collated_data, 1000000));
8483
for (int i = 0; i < boc2.get_root_count(); ++i) {
8584
roots.push_back(boc2.get_root_cell(i));
8685
}
@@ -94,8 +93,7 @@ td::Result<td::BufferSlice> compress_candidate_data(td::Slice block, td::Slice c
9493
td::Result<std::pair<td::BufferSlice, td::BufferSlice>> decompress_candidate_data(td::Slice compressed,
9594
bool improved_compression,
9695
int decompressed_size,
97-
int max_decompressed_size,
98-
int proto_version) {
96+
int max_decompressed_size) {
9997
std::vector<td::Ref<vm::Cell>> roots;
10098
if (!improved_compression) {
10199
TRY_RESULT(decompressed, td::lz4_decompress(compressed, decompressed_size));
@@ -111,8 +109,7 @@ td::Result<std::pair<td::BufferSlice, td::BufferSlice>> decompress_candidate_dat
111109
}
112110
TRY_RESULT(block_data, vm::std_boc_serialize(roots[0], 31));
113111
roots.erase(roots.begin());
114-
int collated_data_mode = proto_version >= 5 ? 2 : 31;
115-
TRY_RESULT(collated_data, vm::std_boc_serialize_multi(std::move(roots), collated_data_mode));
112+
TRY_RESULT(collated_data, vm::std_boc_serialize_multi(std::move(roots), 2));
116113
LOG(DEBUG) << "Decompressing block candidate " << (improved_compression ? "V2:" : ":") << compressed.size() << " -> "
117114
<< block_data.size() + collated_data.size();
118115
return std::make_pair(std::move(block_data), std::move(collated_data));

validator-session/candidate-serializer.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ td::Result<td::BufferSlice> serialize_candidate(const tl_object_ptr<ton_api::val
2424
bool compression_enabled);
2525
td::Result<tl_object_ptr<ton_api::validatorSession_candidate>> deserialize_candidate(td::Slice data,
2626
bool compression_enabled,
27-
int max_decompressed_data_size,
28-
int proto_version);
27+
int max_decompressed_data_size);
2928

3029
td::Result<td::BufferSlice> compress_candidate_data(td::Slice block, td::Slice collated_data,
3130
size_t& decompressed_size);
3231
td::Result<std::pair<td::BufferSlice, td::BufferSlice>> decompress_candidate_data(td::Slice compressed,
3332
bool improved_compression,
3433
int decompressed_size,
35-
int max_decompressed_size,
36-
int proto_version);
34+
int max_decompressed_size);
3735

3836
} // namespace ton::validatorsession

validator-session/validator-session.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ void ValidatorSessionImpl::process_broadcast(PublicKeyHash src, td::BufferSlice
242242
td::Timer deserialize_timer;
243243
auto R =
244244
deserialize_candidate(data, compress_block_candidates_,
245-
description().opts().max_block_size + description().opts().max_collated_data_size + 1024,
246-
description().opts().proto_version);
245+
description().opts().max_block_size + description().opts().max_collated_data_size + 1024);
247246
double deserialize_time = deserialize_timer.elapsed();
248247
if (R.is_error()) {
249248
VLOG(VALIDATOR_SESSION_WARNING) << this << "[node " << src << "][broadcast " << sha256_bits256(data.as_slice())
@@ -1012,8 +1011,7 @@ void ValidatorSessionImpl::downloaded_accepted_candidate(td::uint32 round, const
10121011
}
10131012
auto R =
10141013
deserialize_candidate(result, compress_block_candidates_,
1015-
description().opts().max_block_size + description().opts().max_collated_data_size + 1024,
1016-
description().opts().proto_version);
1014+
description().opts().max_block_size + description().opts().max_collated_data_size + 1024);
10171015
if (R.is_error()) {
10181016
VLOG(VALIDATOR_SESSION_WARNING) << this << ": failed to download accepted candidate " << candidate_id << ": "
10191017
<< R.move_as_error();

validator/collation-manager.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ void CollationManager::tear_down() {
5656
}
5757

5858
void CollationManager::collate_block(CollateParams params, BlockCandidatePriority priority, td::uint64 max_answer_size,
59-
td::CancellationToken cancellation_token, td::Promise<GeneratedCandidate> promise,
60-
int proto_version) {
59+
td::CancellationToken cancellation_token,
60+
td::Promise<GeneratedCandidate> promise) {
6161
if (params.shard.is_masterchain()) {
6262
run_collate_query(std::move(params), manager_, td::Timestamp::in(10.0), std::move(cancellation_token),
6363
promise.wrap([](BlockCandidate&& candidate) {
@@ -67,13 +67,12 @@ void CollationManager::collate_block(CollateParams params, BlockCandidatePriorit
6767
return;
6868
}
6969
collate_shard_block(std::move(params), priority, max_answer_size, std::move(cancellation_token), std::move(promise),
70-
td::Timestamp::in(10.0), proto_version);
70+
td::Timestamp::in(10.0));
7171
}
7272

7373
void CollationManager::collate_shard_block(CollateParams params, BlockCandidatePriority priority,
7474
td::uint64 max_answer_size, td::CancellationToken cancellation_token,
75-
td::Promise<GeneratedCandidate> promise, td::Timestamp timeout,
76-
int proto_version) {
75+
td::Promise<GeneratedCandidate> promise, td::Timestamp timeout) {
7776
bool is_optimistic = params.optimistic_prev_block.not_null();
7877
TRY_STATUS_PROMISE(promise, cancellation_token.check());
7978
ShardInfo* s = select_shard_info(params.shard);
@@ -181,7 +180,7 @@ void CollationManager::collate_shard_block(CollateParams params, BlockCandidateP
181180
delay_action(
182181
[=, promise = std::move(promise)]() mutable {
183182
td::actor::send_closure(SelfId, &CollationManager::collate_shard_block, params, priority, max_answer_size,
184-
cancellation_token, std::move(promise), timeout, proto_version);
183+
cancellation_token, std::move(promise), timeout);
185184
},
186185
retry_at);
187186
};
@@ -214,8 +213,7 @@ void CollationManager::collate_shard_block(CollateParams params, BlockCandidateP
214213
return;
215214
}
216215
TRY_RESULT_PROMISE(P, f, fetch_tl_object<ton_api::collatorNode_Candidate>(data, true));
217-
TRY_RESULT_PROMISE(P, candidate,
218-
deserialize_candidate(std::move(f), td::narrow_cast<int>(max_answer_size), proto_version));
216+
TRY_RESULT_PROMISE(P, candidate, deserialize_candidate(std::move(f), td::narrow_cast<int>(max_answer_size)));
219217
if (candidate.pubkey.as_bits256() != params.creator.as_bits256()) {
220218
P.set_error(td::Status::Error("collate query: block candidate source mismatch"));
221219
return;

validator/collation-manager.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class CollationManager : public td::actor::Actor {
3838
void alarm() override;
3939

4040
void collate_block(CollateParams params, BlockCandidatePriority priority, td::uint64 max_answer_size,
41-
td::CancellationToken cancellation_token, td::Promise<GeneratedCandidate> promise,
42-
int proto_version);
41+
td::CancellationToken cancellation_token, td::Promise<GeneratedCandidate> promise);
4342

4443
void update_options(td::Ref<ValidatorManagerOptions> opts);
4544

@@ -59,7 +58,7 @@ class CollationManager : public td::actor::Actor {
5958

6059
void collate_shard_block(CollateParams params, BlockCandidatePriority priority, td::uint64 max_answer_size,
6160
td::CancellationToken cancellation_token, td::Promise<GeneratedCandidate> promise,
62-
td::Timestamp timeout, int proto_version);
61+
td::Timestamp timeout);
6362

6463
void update_collators_list(const CollatorsList& collators_list);
6564

0 commit comments

Comments
 (0)