2020-02-28 10:28:47 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
2019-11-15 14:02:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "validator/interfaces/db.h"
|
|
|
|
#include "package.hpp"
|
|
|
|
#include "fileref.hpp"
|
|
|
|
|
|
|
|
namespace ton {
|
|
|
|
|
|
|
|
namespace validator {
|
|
|
|
|
|
|
|
class PackageWriter : public td::actor::Actor {
|
|
|
|
public:
|
|
|
|
PackageWriter(std::shared_ptr<Package> package) : package_(std::move(package)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void append(std::string filename, td::BufferSlice data, td::Promise<std::pair<td::uint64, td::uint64>> promise);
|
|
|
|
void set_async_mode(bool mode, td::Promise<td::Unit> promise) {
|
|
|
|
async_mode_ = mode;
|
|
|
|
if (!async_mode_) {
|
|
|
|
package_->sync();
|
|
|
|
}
|
|
|
|
promise.set_value(td::Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<Package> package_;
|
|
|
|
bool async_mode_ = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ArchiveSlice : public td::actor::Actor {
|
|
|
|
public:
|
2020-04-06 20:08:53 +00:00
|
|
|
ArchiveSlice(td::uint32 archive_id, bool key_blocks_only, bool temp, std::string prefix);
|
|
|
|
|
|
|
|
void get_archive_id(BlockSeqno masterchain_seqno, td::Promise<td::uint64> promise) {
|
|
|
|
promise.set_result(archive_id_);
|
|
|
|
}
|
2019-11-15 14:02:37 +00:00
|
|
|
|
|
|
|
void add_handle(BlockHandle handle, td::Promise<td::Unit> promise);
|
|
|
|
void update_handle(BlockHandle handle, td::Promise<td::Unit> promise);
|
2020-04-06 20:08:53 +00:00
|
|
|
void add_file(BlockHandle handle, FileReference ref_id, td::BufferSlice data, td::Promise<td::Unit> promise);
|
2019-11-15 14:02:37 +00:00
|
|
|
void get_handle(BlockIdExt block_id, td::Promise<BlockHandle> promise);
|
2019-11-28 14:44:14 +00:00
|
|
|
void get_temp_handle(BlockIdExt block_id, td::Promise<ConstBlockHandle> promise);
|
2020-04-07 15:35:04 +00:00
|
|
|
void get_file(ConstBlockHandle handle, FileReference ref_id, td::Promise<td::BufferSlice> promise);
|
2019-11-15 14:02:37 +00:00
|
|
|
|
|
|
|
/* from LTDB */
|
2019-11-28 14:44:14 +00:00
|
|
|
void get_block_by_unix_time(AccountIdPrefixFull account_id, UnixTime ts, td::Promise<ConstBlockHandle> promise);
|
|
|
|
void get_block_by_lt(AccountIdPrefixFull account_id, LogicalTime lt, td::Promise<ConstBlockHandle> promise);
|
|
|
|
void get_block_by_seqno(AccountIdPrefixFull account_id, BlockSeqno seqno, td::Promise<ConstBlockHandle> promise);
|
2019-11-15 14:02:37 +00:00
|
|
|
void get_block_common(AccountIdPrefixFull account_id,
|
|
|
|
std::function<td::int32(ton_api::db_lt_desc_value &)> compare_desc,
|
|
|
|
std::function<td::int32(ton_api::db_lt_el_value &)> compare, bool exact,
|
2019-11-28 14:44:14 +00:00
|
|
|
td::Promise<ConstBlockHandle> promise);
|
2019-11-15 14:02:37 +00:00
|
|
|
|
2020-04-06 20:08:53 +00:00
|
|
|
void get_slice(td::uint64 archive_id, td::uint64 offset, td::uint32 limit, td::Promise<td::BufferSlice> promise);
|
2019-11-15 14:02:37 +00:00
|
|
|
|
|
|
|
void start_up() override;
|
|
|
|
void destroy(td::Promise<td::Unit> promise);
|
|
|
|
|
|
|
|
void begin_transaction();
|
|
|
|
void commit_transaction();
|
|
|
|
void set_async_mode(bool mode, td::Promise<td::Unit> promise);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void written_data(BlockHandle handle, td::Promise<td::Unit> promise);
|
|
|
|
void add_file_cont(FileReference ref_id, td::uint64 offset, td::uint64 size, td::Promise<td::Unit> promise);
|
|
|
|
|
|
|
|
/* ltdb */
|
|
|
|
td::BufferSlice get_db_key_lt_desc(ShardIdFull shard);
|
|
|
|
td::BufferSlice get_db_key_lt_el(ShardIdFull shard, td::uint32 idx);
|
|
|
|
td::BufferSlice get_db_key_block_info(BlockIdExt block_id);
|
|
|
|
td::BufferSlice get_lt_from_db(ShardIdFull shard, td::uint32 idx);
|
|
|
|
|
2020-04-06 20:08:53 +00:00
|
|
|
td::uint32 archive_id_;
|
|
|
|
|
2019-11-15 14:02:37 +00:00
|
|
|
bool key_blocks_only_;
|
|
|
|
bool temp_;
|
|
|
|
|
|
|
|
bool destroyed_ = false;
|
|
|
|
bool async_mode_ = false;
|
|
|
|
bool huge_transaction_started_ = false;
|
|
|
|
td::uint32 huge_transaction_size_ = 0;
|
|
|
|
|
|
|
|
std::string prefix_;
|
|
|
|
std::shared_ptr<td::KeyValue> kv_;
|
2020-04-07 15:35:04 +00:00
|
|
|
|
|
|
|
struct PackageInfo {
|
|
|
|
PackageInfo(std::shared_ptr<Package> package, td::actor::ActorOwn<PackageWriter> writer, std::string path,
|
|
|
|
td::uint32 idx)
|
|
|
|
: package(std::move(package)), writer(std ::move(writer)), path(std::move(path)), idx(idx) {
|
|
|
|
}
|
|
|
|
std::shared_ptr<Package> package;
|
|
|
|
td::actor::ActorOwn<PackageWriter> writer;
|
|
|
|
std::string path;
|
|
|
|
td::uint32 idx;
|
|
|
|
};
|
|
|
|
std::vector<PackageInfo> packages_;
|
|
|
|
|
|
|
|
PackageInfo &choose_package(BlockSeqno masterchain_seqno);
|
2019-11-15 14:02:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace validator
|
|
|
|
|
|
|
|
} // namespace ton
|