mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Exp/compress candidates (#942)
* Compress block candidates in validator-session * Compress blocks in full-node (disabled for now) --------- Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
9452c367e4
commit
0bcebe8a0e
21 changed files with 548 additions and 112 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "td/utils/overloaded.h"
|
||||
#include "ton/ton-io.hpp"
|
||||
#include "validator/full-node.h"
|
||||
#include "full-node-serializer.hpp"
|
||||
|
||||
namespace ton {
|
||||
|
||||
|
@ -219,52 +220,54 @@ void DownloadBlockNew::got_data(td::BufferSlice data) {
|
|||
}
|
||||
|
||||
auto f = F.move_as_ok();
|
||||
if (f->get_id() == ton_api::tonNode_dataFullEmpty::ID) {
|
||||
abort_query(td::Status::Error(ErrorCode::notready, "node doesn't have this block"));
|
||||
return;
|
||||
}
|
||||
BlockIdExt id;
|
||||
td::BufferSlice proof, block_data;
|
||||
bool is_link;
|
||||
td::Status S = deserialize_block_full(*f, id, proof, block_data, is_link, overlay::Overlays::max_fec_broadcast_size());
|
||||
if (S.is_error()) {
|
||||
abort_query(S.move_as_error_prefix("cannot deserialize block: "));
|
||||
return;
|
||||
}
|
||||
|
||||
ton_api::downcast_call(
|
||||
*f.get(),
|
||||
td::overloaded(
|
||||
[&](ton_api::tonNode_dataFullEmpty &x) {
|
||||
abort_query(td::Status::Error(ErrorCode::notready, "node doesn't have this block"));
|
||||
},
|
||||
[&, self = this](ton_api::tonNode_dataFull &x) {
|
||||
if (!allow_partial_proof_ && x.is_link_) {
|
||||
abort_query(td::Status::Error(ErrorCode::notready, "node doesn't have proof for this block"));
|
||||
return;
|
||||
}
|
||||
auto id = create_block_id(x.id_);
|
||||
if (block_id_.is_valid() && id != block_id_) {
|
||||
abort_query(td::Status::Error(ErrorCode::notready, "received data for wrong block"));
|
||||
return;
|
||||
}
|
||||
block_.id = id;
|
||||
block_.data = std::move(x.block_);
|
||||
if (td::sha256_bits256(block_.data.as_slice()) != id.file_hash) {
|
||||
abort_query(td::Status::Error(ErrorCode::notready, "received data with bad hash"));
|
||||
return;
|
||||
}
|
||||
if (!allow_partial_proof_ && is_link) {
|
||||
abort_query(td::Status::Error(ErrorCode::notready, "node doesn't have proof for this block"));
|
||||
return;
|
||||
}
|
||||
if (block_id_.is_valid() && id != block_id_) {
|
||||
abort_query(td::Status::Error(ErrorCode::notready, "received data for wrong block"));
|
||||
return;
|
||||
}
|
||||
block_.id = id;
|
||||
block_.data = std::move(block_data);
|
||||
if (td::sha256_bits256(block_.data.as_slice()) != id.file_hash) {
|
||||
abort_query(td::Status::Error(ErrorCode::notready, "received data with bad hash"));
|
||||
return;
|
||||
}
|
||||
|
||||
auto P = td::PromiseCreator::lambda([SelfId = actor_id(self)](td::Result<td::Unit> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(SelfId, &DownloadBlockNew::abort_query,
|
||||
R.move_as_error_prefix("received bad proof: "));
|
||||
} else {
|
||||
td::actor::send_closure(SelfId, &DownloadBlockNew::checked_block_proof);
|
||||
}
|
||||
});
|
||||
if (block_id_.is_valid()) {
|
||||
if (x.is_link_) {
|
||||
td::actor::send_closure(validator_manager_, &ValidatorManagerInterface::validate_block_proof_link,
|
||||
block_id_, std::move(x.proof_), std::move(P));
|
||||
} else {
|
||||
td::actor::send_closure(validator_manager_, &ValidatorManagerInterface::validate_block_proof, block_id_,
|
||||
std::move(x.proof_), std::move(P));
|
||||
}
|
||||
} else {
|
||||
CHECK(!x.is_link_);
|
||||
td::actor::send_closure(validator_manager_, &ValidatorManagerInterface::validate_block_is_next_proof,
|
||||
prev_id_, id, std::move(x.proof_), std::move(P));
|
||||
}
|
||||
}));
|
||||
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<td::Unit> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(SelfId, &DownloadBlockNew::abort_query, R.move_as_error_prefix("received bad proof: "));
|
||||
} else {
|
||||
td::actor::send_closure(SelfId, &DownloadBlockNew::checked_block_proof);
|
||||
}
|
||||
});
|
||||
if (block_id_.is_valid()) {
|
||||
if (is_link) {
|
||||
td::actor::send_closure(validator_manager_, &ValidatorManagerInterface::validate_block_proof_link, block_id_,
|
||||
std::move(proof), std::move(P));
|
||||
} else {
|
||||
td::actor::send_closure(validator_manager_, &ValidatorManagerInterface::validate_block_proof, block_id_,
|
||||
std::move(proof), std::move(P));
|
||||
}
|
||||
} else {
|
||||
CHECK(!is_link);
|
||||
td::actor::send_closure(validator_manager_, &ValidatorManagerInterface::validate_block_is_next_proof, prev_id_, id,
|
||||
std::move(proof), std::move(P));
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadBlockNew::got_data_from_db(td::BufferSlice data) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue