1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

integrating the existing state of TON Storage / TON Payments / CPS Fift development branches

This commit is contained in:
ton 2020-05-27 22:10:46 +04:00
parent 040df63c98
commit 4e2624459b
153 changed files with 10760 additions and 1695 deletions

View file

@ -48,7 +48,7 @@ Cell::LoadedCell load_cell_nothrow(const Ref<Cell>& ref) {
auto res = ref->load_cell();
if (res.is_ok()) {
auto ld = res.move_as_ok();
CHECK(ld.virt.get_virtualization() == 0 || ld.data_cell->special_type() != Cell::SpecialType::PrunnedBranch);
//CHECK(ld.virt.get_virtualization() == 0 || ld.data_cell->special_type() != Cell::SpecialType::PrunnedBranch);
return ld;
}
return {};
@ -58,7 +58,7 @@ Cell::LoadedCell load_cell_nothrow(const Ref<Cell>& ref, int mode) {
auto res = ref->load_cell();
if (res.is_ok()) {
auto ld = res.move_as_ok();
CHECK(ld.virt.get_virtualization() == 0 || ld.data_cell->special_type() != Cell::SpecialType::PrunnedBranch);
//CHECK(ld.virt.get_virtualization() == 0 || ld.data_cell->special_type() != Cell::SpecialType::PrunnedBranch);
if ((mode >> (ld.data_cell->is_special() ? 1 : 0)) & 1) {
return ld;
}

View file

@ -79,6 +79,19 @@ td::Result<td::string> CellString::load(CellSlice &cs, unsigned int top_bits) {
CHECK(to.offs == (int)size);
return res;
}
td::Result<td::Ref<vm::Cell>> CellString::create(td::Slice slice, unsigned int top_bits) {
vm::CellBuilder cb;
TRY_STATUS(store(cb, slice, top_bits));
return cb.finalize();
}
bool CellString::fetch_to(CellSlice &cs, std::string &res, unsigned int top_bits) {
auto r_str = load(cs, top_bits);
if (r_str.is_error()) {
return false;
}
res = r_str.move_as_ok();
return true;
}
td::Status CellText::store(CellBuilder &cb, td::Slice slice, unsigned int top_bits) {
td::uint32 size = td::narrow_cast<td::uint32>(slice.size() * 8);
@ -154,4 +167,17 @@ td::Result<td::string> CellText::load(CellSlice &cs) {
CHECK(to.offs == (int)size);
return res;
}
td::Result<td::Ref<vm::Cell>> CellText::create(td::Slice slice, unsigned int top_bits) {
vm::CellBuilder cb;
TRY_STATUS(store(cb, slice, top_bits));
return cb.finalize();
}
bool CellText::fetch_to(CellSlice &cs, std::string &res) {
auto r_str = load(cs);
if (r_str.is_error()) {
return false;
}
res = r_str.move_as_ok();
return true;
}
} // namespace vm

View file

@ -31,11 +31,8 @@ class CellString {
static td::Status store(CellBuilder &cb, td::Slice slice, unsigned int top_bits = Cell::max_bits);
static td::Status store(CellBuilder &cb, td::BitSlice slice, unsigned int top_bits = Cell::max_bits);
static td::Result<td::string> load(CellSlice &cs, unsigned int top_bits = Cell::max_bits);
static td::Result<td::Ref<vm::Cell>> create(td::Slice slice, unsigned int top_bits = Cell::max_bits) {
vm::CellBuilder cb;
TRY_STATUS(store(cb, slice, top_bits));
return cb.finalize();
}
static td::Result<td::Ref<vm::Cell>> create(td::Slice slice, unsigned int top_bits = Cell::max_bits);
static bool fetch_to(CellSlice &cs, std::string &res, unsigned int top_bits = Cell::max_bits);
private:
template <class F>
@ -50,11 +47,8 @@ class CellText {
static td::Status store(CellBuilder &cb, td::Slice slice, unsigned int top_bits = Cell::max_bits);
static td::Status store(CellBuilder &cb, td::BitSlice slice, unsigned int top_bits = Cell::max_bits);
static td::Result<td::string> load(CellSlice &cs);
static td::Result<td::Ref<vm::Cell>> create(td::Slice slice, unsigned int top_bits = Cell::max_bits) {
vm::CellBuilder cb;
TRY_STATUS(store(cb, slice, top_bits));
return cb.finalize();
}
static td::Result<td::Ref<vm::Cell>> create(td::Slice slice, unsigned int top_bits = Cell::max_bits);
static bool fetch_to(CellSlice &cs, std::string &res);
private:
template <class F>

View file

@ -187,9 +187,9 @@ class StaticBagOfCellsDbBaselineImpl : public StaticBagOfCellsDb {
}
};
td::Result<std::shared_ptr<StaticBagOfCellsDb>> StaticBagOfCellsDbBaseline::create(std::unique_ptr<BlobView> data) {
std::string buf(data->size(), '\0');
TRY_RESULT(slice, data->view(buf, 0));
td::Result<std::shared_ptr<StaticBagOfCellsDb>> StaticBagOfCellsDbBaseline::create(td::BlobView data) {
std::string buf(data.size(), '\0');
TRY_RESULT(slice, data.view(buf, 0));
return create(slice);
}
@ -211,7 +211,7 @@ td::Result<std::shared_ptr<StaticBagOfCellsDb>> StaticBagOfCellsDbBaseline::crea
//
class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
public:
explicit StaticBagOfCellsDbLazyImpl(std::unique_ptr<BlobView> data, StaticBagOfCellsDbLazy::Options options)
explicit StaticBagOfCellsDbLazyImpl(td::BlobView data, StaticBagOfCellsDbLazy::Options options)
: data_(std::move(data)), options_(std::move(options)) {
get_thread_safe_counter().add(1);
}
@ -240,7 +240,7 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
private:
std::atomic<bool> should_cache_cells_{true};
std::unique_ptr<BlobView> data_;
td::BlobView data_;
StaticBagOfCellsDbLazy::Options options_;
bool has_info_{false};
BagOfCells::Info info_;
@ -313,8 +313,8 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
char arr[8];
td::RwMutex::ReadLock guard;
if (info_.has_index) {
TRY_RESULT(new_offset_view, data_->view(td::MutableSlice(arr, info_.offset_byte_size),
info_.index_offset + idx * info_.offset_byte_size));
TRY_RESULT(new_offset_view, data_.view(td::MutableSlice(arr, info_.offset_byte_size),
info_.index_offset + idx * info_.offset_byte_size));
offset_view = new_offset_view;
} else {
guard = index_data_rw_mutex_.lock_read().move_as_ok();
@ -331,8 +331,8 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
return 0;
}
char arr[8];
TRY_RESULT(idx_view, data_->view(td::MutableSlice(arr, info_.ref_byte_size),
info_.roots_offset + root_i * info_.ref_byte_size));
TRY_RESULT(idx_view, data_.view(td::MutableSlice(arr, info_.ref_byte_size),
info_.roots_offset + root_i * info_.ref_byte_size));
CHECK(idx_view.size() == (size_t)info_.ref_byte_size);
return info_.read_ref(idx_view.ubegin());
}
@ -369,17 +369,17 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
return td::Status::OK();
}
std::string header(1000, '\0');
TRY_RESULT(header_view, data_->view(td::MutableSlice(header).truncate(data_->size()), 0))
TRY_RESULT(header_view, data_.view(td::MutableSlice(header).truncate(data_.size()), 0))
auto parse_res = info_.parse_serialized_header(header_view);
if (parse_res <= 0) {
return td::Status::Error("bag-of-cell error: failed to read header");
}
if (info_.total_size < data_->size()) {
if (info_.total_size < data_.size()) {
return td::Status::Error("bag-of-cell error: not enough data");
}
if (options_.check_crc32c && info_.has_crc32c) {
std::string buf(td::narrow_cast<std::size_t>(info_.total_size), '\0');
TRY_RESULT(data, data_->view(td::MutableSlice(buf), 0));
TRY_RESULT(data, data_.view(td::MutableSlice(buf), 0));
unsigned crc_computed = td::crc32c(td::Slice{data.ubegin(), data.uend() - 4});
unsigned crc_stored = td::as<unsigned>(data.uend() - 4);
if (crc_computed != crc_stored) {
@ -407,8 +407,8 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
auto buf_slice = td::MutableSlice(buf.data(), buf.size());
for (; index_i_ <= idx; index_i_++) {
auto offset = td::narrow_cast<size_t>(info_.data_offset + index_offset_);
CHECK(data_->size() >= offset);
TRY_RESULT(cell, data_->view(buf_slice.copy().truncate(data_->size() - offset), offset));
CHECK(data_.size() >= offset);
TRY_RESULT(cell, data_.view(buf_slice.copy().truncate(data_.size() - offset), offset));
CellSerializationInfo cell_info;
TRY_STATUS(cell_info.init(cell, info_.ref_byte_size));
index_offset_ += cell_info.end_offset;
@ -455,7 +455,7 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
TRY_RESULT(cell_location, get_cell_location(idx));
auto buf = alloc(cell_location.end - cell_location.begin);
TRY_RESULT(cell_slice, data_->view(buf.as_slice(), cell_location.begin));
TRY_RESULT(cell_slice, data_.view(buf.as_slice(), cell_location.begin));
TRY_RESULT(res, deserialize_any_cell(idx, cell_slice, cell_location.should_cache));
return std::move(res);
}
@ -470,7 +470,7 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
TRY_RESULT(cell_location, get_cell_location(idx));
auto buf = alloc(cell_location.end - cell_location.begin);
TRY_RESULT(cell_slice, data_->view(buf.as_slice(), cell_location.begin));
TRY_RESULT(cell_slice, data_.view(buf.as_slice(), cell_location.begin));
TRY_RESULT(res, deserialize_data_cell(idx, cell_slice, cell_location.should_cache));
return std::move(res);
}
@ -528,18 +528,17 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
}
};
td::Result<std::shared_ptr<StaticBagOfCellsDb>> StaticBagOfCellsDbLazy::create(std::unique_ptr<BlobView> data,
Options options) {
td::Result<std::shared_ptr<StaticBagOfCellsDb>> StaticBagOfCellsDbLazy::create(td::BlobView data, Options options) {
return std::make_shared<StaticBagOfCellsDbLazyImpl>(std::move(data), std::move(options));
}
td::Result<std::shared_ptr<StaticBagOfCellsDb>> StaticBagOfCellsDbLazy::create(td::BufferSlice data, Options options) {
return std::make_shared<StaticBagOfCellsDbLazyImpl>(vm::BufferSliceBlobView::create(std::move(data)),
return std::make_shared<StaticBagOfCellsDbLazyImpl>(td::BufferSliceBlobView::create(std::move(data)),
std::move(options));
}
td::Result<std::shared_ptr<StaticBagOfCellsDb>> StaticBagOfCellsDbLazy::create(std::string data, Options options) {
return create(BufferSliceBlobView::create(td::BufferSlice(data)), std::move(options));
return create(td::BufferSliceBlobView::create(td::BufferSlice(data)), std::move(options));
}
} // namespace vm

View file

@ -19,7 +19,7 @@
#pragma once
#include "vm/cells.h"
#include "vm/db/BlobView.h"
#include "td/db/utils/BlobView.h"
#include "td/utils/Status.h"
@ -41,7 +41,7 @@ class StaticBagOfCellsDb : public std::enable_shared_from_this<StaticBagOfCellsD
class StaticBagOfCellsDbBaseline {
public:
static td::Result<std::shared_ptr<StaticBagOfCellsDb>> create(std::unique_ptr<BlobView> data);
static td::Result<std::shared_ptr<StaticBagOfCellsDb>> create(td::BlobView data);
static td::Result<std::shared_ptr<StaticBagOfCellsDb>> create(td::Slice data);
};
@ -52,7 +52,7 @@ class StaticBagOfCellsDbLazy {
}
bool check_crc32c{false};
};
static td::Result<std::shared_ptr<StaticBagOfCellsDb>> create(std::unique_ptr<BlobView> data, Options options = {});
static td::Result<std::shared_ptr<StaticBagOfCellsDb>> create(td::BlobView data, Options options = {});
static td::Result<std::shared_ptr<StaticBagOfCellsDb>> create(td::BufferSlice data, Options options = {});
static td::Result<std::shared_ptr<StaticBagOfCellsDb>> create(std::string data, Options options = {});
};