2019-09-07 10:03:22 +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/>.
|
|
|
|
|
2020-04-10 19:06:01 +00:00
|
|
|
Copyright 2017-2020 Telegram Systems LLP
|
2019-09-07 10:03:22 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "vm/cells.h"
|
|
|
|
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/Status.h"
|
2022-06-01 07:03:50 +00:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
2019-09-07 10:03:22 +00:00
|
|
|
|
|
|
|
namespace vm {
|
|
|
|
class CellLoader;
|
|
|
|
class CellStorer;
|
|
|
|
} // namespace vm
|
|
|
|
|
|
|
|
namespace vm {
|
|
|
|
class ExtCellCreator {
|
|
|
|
public:
|
|
|
|
virtual ~ExtCellCreator() = default;
|
|
|
|
virtual td::Result<Ref<Cell>> ext_cell(Cell::LevelMask level_mask, td::Slice hash, td::Slice depth) = 0;
|
|
|
|
};
|
|
|
|
|
2022-05-24 18:17:11 +00:00
|
|
|
class CellDbReader {
|
|
|
|
public:
|
|
|
|
virtual ~CellDbReader() = default;
|
|
|
|
virtual td::Result<Ref<DataCell>> load_cell(td::Slice hash) = 0;
|
|
|
|
};
|
|
|
|
|
2019-09-07 10:03:22 +00:00
|
|
|
class DynamicBagOfCellsDb {
|
|
|
|
public:
|
|
|
|
virtual ~DynamicBagOfCellsDb() = default;
|
|
|
|
virtual td::Result<Ref<DataCell>> load_cell(td::Slice hash) = 0;
|
|
|
|
struct Stats {
|
|
|
|
td::int64 cells_total_count{0};
|
|
|
|
td::int64 cells_total_size{0};
|
|
|
|
void apply_diff(Stats diff) {
|
|
|
|
cells_total_count += diff.cells_total_count;
|
|
|
|
cells_total_size += diff.cells_total_size;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
virtual void inc(const Ref<Cell> &old_root) = 0;
|
|
|
|
virtual void dec(const Ref<Cell> &old_root) = 0;
|
|
|
|
|
|
|
|
virtual td::Status prepare_commit() = 0;
|
|
|
|
virtual Stats get_stats_diff() = 0;
|
|
|
|
virtual td::Status commit(CellStorer &) = 0;
|
2022-05-24 18:17:11 +00:00
|
|
|
virtual std::shared_ptr<CellDbReader> get_cell_db_reader() = 0;
|
2019-09-07 10:03:22 +00:00
|
|
|
|
|
|
|
// restart with new loader will also reset stats_diff
|
|
|
|
virtual td::Status set_loader(std::unique_ptr<CellLoader> loader) = 0;
|
|
|
|
|
2023-12-08 11:20:17 +00:00
|
|
|
virtual void set_celldb_compress_depth(td::uint32 value) = 0;
|
|
|
|
virtual vm::ExtCellCreator& as_ext_cell_creator() = 0;
|
|
|
|
|
2019-09-07 10:03:22 +00:00
|
|
|
static std::unique_ptr<DynamicBagOfCellsDb> create();
|
2022-06-01 07:03:50 +00:00
|
|
|
|
|
|
|
class AsyncExecutor {
|
|
|
|
public:
|
|
|
|
virtual ~AsyncExecutor() {}
|
|
|
|
virtual void execute_async(std::function<void()> f) = 0;
|
|
|
|
virtual void execute_sync(std::function<void()> f) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual void load_cell_async(td::Slice hash, std::shared_ptr<AsyncExecutor> executor,
|
|
|
|
td::Promise<Ref<DataCell>> promise) = 0;
|
2019-09-07 10:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace vm
|