mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
updated tonlib, new fullnode queries
This commit is contained in:
parent
87ccb27b70
commit
a1e352d894
40 changed files with 1188 additions and 175 deletions
114
validator/full-node-shard-queries.hpp
Normal file
114
validator/full-node-shard-queries.hpp
Normal file
|
@ -0,0 +1,114 @@
|
|||
#pragma once
|
||||
|
||||
#include "validator/validator.h"
|
||||
#include "ton/ton-tl.hpp"
|
||||
|
||||
namespace ton {
|
||||
|
||||
namespace validator {
|
||||
|
||||
namespace fullnode {
|
||||
|
||||
class BlockFullSender : public td::actor::Actor {
|
||||
public:
|
||||
BlockFullSender(BlockIdExt block_id, bool next, td::actor::ActorId<ValidatorManagerInterface> manager,
|
||||
td::Promise<td::BufferSlice> promise)
|
||||
: block_id_(block_id), next_(next), manager_(manager), promise_(std::move(promise)) {
|
||||
}
|
||||
void abort_query(td::Status error) {
|
||||
promise_.set_value(create_serialize_tl_object<ton_api::tonNode_dataFullEmpty>());
|
||||
stop();
|
||||
}
|
||||
void finish_query() {
|
||||
promise_.set_value(create_serialize_tl_object<ton_api::tonNode_dataFull>(
|
||||
create_tl_block_id(block_id_), std::move(proof_), std::move(data_), is_proof_link_));
|
||||
stop();
|
||||
}
|
||||
void start_up() override {
|
||||
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<BlockHandle> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(SelfId, &BlockFullSender::abort_query, R.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure(SelfId, &BlockFullSender::got_block_handle, R.move_as_ok());
|
||||
}
|
||||
});
|
||||
td::actor::send_closure(manager_, &ValidatorManagerInterface::get_block_handle, block_id_, false, std::move(P));
|
||||
}
|
||||
|
||||
void got_block_handle(BlockHandle handle) {
|
||||
if (next_) {
|
||||
if (!handle->inited_next_left()) {
|
||||
return abort_query(td::Status::Error(ErrorCode::notready, "next not known"));
|
||||
}
|
||||
next_ = false;
|
||||
block_id_ = handle->one_next(true);
|
||||
start_up();
|
||||
return;
|
||||
}
|
||||
if (!handle->received() || (!handle->inited_proof() && !handle->inited_proof_link()) || handle->deleted()) {
|
||||
return abort_query(td::Status::Error(ErrorCode::notready, "not in db"));
|
||||
}
|
||||
handle_ = std::move(handle);
|
||||
is_proof_link_ = !handle_->inited_proof();
|
||||
|
||||
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<td::Ref<BlockData>> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(SelfId, &BlockFullSender::abort_query, R.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure(SelfId, &BlockFullSender::got_block_data, R.move_as_ok()->data());
|
||||
}
|
||||
});
|
||||
td::actor::send_closure(manager_, &ValidatorManagerInterface::get_block_data_from_db, handle_, std::move(P));
|
||||
|
||||
if (!is_proof_link_) {
|
||||
auto Q = td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<td::Ref<Proof>> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(SelfId, &BlockFullSender::abort_query, R.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure(SelfId, &BlockFullSender::got_block_proof, R.move_as_ok()->data());
|
||||
}
|
||||
});
|
||||
td::actor::send_closure(manager_, &ValidatorManagerInterface::get_block_proof_from_db, handle_, std::move(Q));
|
||||
} else {
|
||||
auto Q = td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<td::Ref<ProofLink>> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(SelfId, &BlockFullSender::abort_query, R.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure(SelfId, &BlockFullSender::got_block_proof, R.move_as_ok()->data());
|
||||
}
|
||||
});
|
||||
td::actor::send_closure(manager_, &ValidatorManagerInterface::get_block_proof_link_from_db, handle_,
|
||||
std::move(Q));
|
||||
}
|
||||
}
|
||||
|
||||
void got_block_data(td::BufferSlice data) {
|
||||
data_ = std::move(data);
|
||||
if (!proof_.empty()) {
|
||||
finish_query();
|
||||
}
|
||||
}
|
||||
|
||||
void got_block_proof(td::BufferSlice data) {
|
||||
proof_ = std::move(data);
|
||||
if (!data_.empty()) {
|
||||
finish_query();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
BlockIdExt block_id_;
|
||||
bool next_;
|
||||
BlockHandle handle_;
|
||||
bool is_proof_link_;
|
||||
td::BufferSlice proof_;
|
||||
td::BufferSlice data_;
|
||||
td::actor::ActorId<ValidatorManagerInterface> manager_;
|
||||
td::Promise<td::BufferSlice> promise_;
|
||||
};
|
||||
|
||||
} // namespace fullnode
|
||||
|
||||
} // namespace validator
|
||||
|
||||
} // namespace ton
|
Loading…
Add table
Add a link
Reference in a new issue