/*
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 .
Copyright 2017-2019 Telegram Systems LLP
*/
#pragma once
#include "td/actor/actor.h"
#include "td/db/KeyValueAsync.h"
#include "ton/ton-types.h"
#include "blockdb.hpp"
#include "celldb.hpp"
#include "filedb.hpp"
#include "ltdb.hpp"
#include "statedb.hpp"
#include "staticfilesdb.hpp"
namespace ton {
namespace validator {
class RootDb : public Db {
public:
enum class Flags : td::uint32 { f_started = 1, f_ready = 2, f_switched = 4, f_archived = 8 };
RootDb(td::actor::ActorId validator_manager, std::string root_path, td::uint32 depth)
: validator_manager_(validator_manager), root_path_(std::move(root_path)), depth_(depth) {
}
void start_up() override;
void store_block_data(BlockHandle handle, td::Ref block, td::Promise promise) override;
void get_block_data(BlockHandle handle, td::Promise> promise) override;
void store_block_signatures(BlockHandle handle, td::Ref data,
td::Promise promise) override;
void get_block_signatures(BlockHandle handle, td::Promise> promise) override;
void store_block_proof(BlockHandle handle, td::Ref proof, td::Promise promise) override;
void get_block_proof(BlockHandle handle, td::Promise> promise) override;
void store_block_proof_link(BlockHandle handle, td::Ref proof, td::Promise promise) override;
void get_block_proof_link(BlockHandle handle, td::Promise> promise) override;
void store_block_candidate(BlockCandidate candidate, td::Promise promise) override;
void get_block_candidate(PublicKey source, BlockIdExt id, FileHash collated_data_file_hash,
td::Promise promise) override;
void store_block_state(BlockHandle handle, td::Ref state,
td::Promise> promise) override;
void get_block_state(BlockHandle handle, td::Promise> promise) override;
void store_block_handle(BlockHandle handle, td::Promise promise) override;
void get_block_handle(BlockIdExt id, td::Promise promise) override;
void get_block_handle_external(BlockIdExt id, bool force, td::Promise promise) {
td::actor::send_closure(validator_manager_, &ValidatorManager::get_block_handle, id, force, std::move(promise));
}
void store_persistent_state_file(BlockIdExt block_id, BlockIdExt masterchain_block_id, td::BufferSlice state,
td::Promise promise) override;
void get_persistent_state_file(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise promise) override;
void check_persistent_state_file_exists(BlockIdExt block_id, BlockIdExt masterchain_block_id,
td::Promise promise) override;
void store_zero_state_file(BlockIdExt block_id, td::BufferSlice state, td::Promise promise) override;
void get_zero_state_file(BlockIdExt block_id, td::Promise promise) override;
void check_zero_state_file_exists(BlockIdExt block_id, td::Promise promise) override;
void try_get_static_file(FileHash file_hash, td::Promise promise) override;
void apply_block(BlockHandle handle, td::Promise promise) override;
void get_block_by_lt(AccountIdPrefixFull account, LogicalTime lt, td::Promise promise) override;
void get_block_by_unix_time(AccountIdPrefixFull account, UnixTime ts, td::Promise promise) override;
void get_block_by_seqno(AccountIdPrefixFull account, BlockSeqno seqno, td::Promise promise) override;
void update_init_masterchain_block(BlockIdExt block, td::Promise promise) override;
void get_init_masterchain_block(td::Promise promise) override;
void update_gc_masterchain_block(BlockIdExt block, td::Promise promise) override;
void get_gc_masterchain_block(td::Promise promise) override;
void update_shard_client_state(BlockIdExt masterchain_block_id, td::Promise promise) override;
void get_shard_client_state(td::Promise promise) override;
void update_destroyed_validator_sessions(std::vector sessions,
td::Promise promise) override;
void get_destroyed_validator_sessions(td::Promise> promise) override;
void update_async_serializer_state(AsyncSerializerState state, td::Promise promise) override;
void get_async_serializer_state(td::Promise promise) override;
void archive(BlockIdExt block_id, td::Promise promise) override;
void allow_state_gc(BlockIdExt block_id, td::Promise promise);
void allow_block_gc(BlockIdExt block_id, td::Promise promise);
void allow_gc(FileDb::RefId ref_id, bool is_archive, td::Promise promise);
private:
td::actor::ActorId validator_manager_;
std::string root_path_;
td::uint32 depth_;
td::actor::ActorOwn cell_db_;
td::actor::ActorOwn block_db_;
td::actor::ActorOwn file_db_;
td::actor::ActorOwn archive_db_;
td::actor::ActorOwn lt_db_;
td::actor::ActorOwn state_db_;
td::actor::ActorOwn static_files_db_;
};
} // namespace validator
} // namespace ton