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

updated tonlib + fixes in vm

This commit is contained in:
ton 2020-02-20 19:56:18 +04:00
parent 28735ddc9e
commit efd47af432
42 changed files with 750 additions and 307 deletions

View file

@ -52,7 +52,7 @@ Ref<DataCell> CellBuilder::finalize_copy(bool special) const {
}
auto res = DataCell::create(data, size(), td::span(refs.data(), size_refs()), special);
if (res.is_error()) {
LOG(ERROR) << res.error();
LOG(DEBUG) << res.error();
throw CellWriteError{};
}
auto cell = res.move_as_ok();
@ -60,7 +60,7 @@ Ref<DataCell> CellBuilder::finalize_copy(bool special) const {
if (vm_state_interface) {
vm_state_interface->register_new_cell(cell);
if (cell.is_null()) {
LOG(ERROR) << "cannot register new data cell";
LOG(DEBUG) << "cannot register new data cell";
throw CellWriteError{};
}
}
@ -71,7 +71,7 @@ Ref<DataCell> CellBuilder::finalize_novm(bool special) {
auto res = DataCell::create(data, size(), td::mutable_span(refs.data(), size_refs()), special);
bits = refs_cnt = 0;
if (res.is_error()) {
LOG(ERROR) << res.error();
LOG(DEBUG) << res.error();
throw CellWriteError{};
}
CHECK(res.ok().not_null());
@ -87,7 +87,7 @@ Ref<DataCell> CellBuilder::finalize(bool special) {
auto cell = finalize_novm(special);
vm_state_interface->register_new_cell(cell);
if (cell.is_null()) {
LOG(ERROR) << "cannot register new data cell";
LOG(DEBUG) << "cannot register new data cell";
throw CellWriteError{};
}
return cell;
@ -102,6 +102,7 @@ Ref<Cell> CellBuilder::create_pruned_branch(Ref<Cell> cell, td::uint32 new_level
}
return do_create_pruned_branch(std::move(cell), new_level, virt_level);
}
Ref<DataCell> CellBuilder::do_create_pruned_branch(Ref<Cell> cell, td::uint32 new_level, td::uint32 virt_level) {
auto level_mask = cell->get_level_mask().apply(virt_level);
auto level = level_mask.get_level();
@ -386,6 +387,14 @@ CellBuilder& CellBuilder::store_ref(Ref<Cell> ref) {
return ensure_pass(store_ref_bool(std::move(ref)));
}
td::uint16 CellBuilder::get_depth() const {
int d = 0;
for (unsigned i = 0; i < refs_cnt; i++) {
d = std::max(d, 1 + refs[i]->get_depth());
}
return static_cast<td::uint16>(d);
}
bool CellBuilder::append_data_cell_bool(const DataCell& cell) {
unsigned len = cell.size();
if (can_extend_by(len, cell.size_refs())) {

View file

@ -14,7 +14,7 @@
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-2019 Telegram Systems LLP
Copyright 2017-2020 Telegram Systems LLP
*/
#pragma once
#include "vm/cells/DataCell.h"
@ -78,6 +78,7 @@ class CellBuilder : public td::CntObject {
const unsigned char* get_data() const {
return data;
}
td::uint16 get_depth() const;
td::ConstBitPtr data_bits() const {
return data;
}

View file

@ -776,6 +776,14 @@ bool CellSlice::fetch_maybe_ref(Ref<vm::Cell>& res) {
}
}
td::uint16 CellSlice::get_depth() const {
int d = 0;
for (unsigned i = 0; i < size_refs(); ++i) {
d = std::max(d, prefetch_ref(i)->get_depth() + 1);
}
return static_cast<td::uint16>(d);
}
bool CellSlice::begins_with(unsigned bits, unsigned long long value) const {
return have(bits) && !((prefetch_ulong(bits) ^ value) & ((1ULL << bits) - 1));
}
@ -980,13 +988,18 @@ void CellSlice::dump_hex(std::ostream& os, int mode, bool endl) const {
}
}
void CellSlice::print_rec(std::ostream& os, int indent) const {
bool CellSlice::print_rec(std::ostream& os, int* limit, int indent) const {
for (int i = 0; i < indent; i++) {
os << ' ';
}
if (!limit || *limit <= 0) {
os << "<cell output limit reached>" << std::endl;
return false;
}
--*limit;
if (cell.is_null()) {
os << "NULL" << std::endl;
return;
return true;
}
if (is_special()) {
os << "SPECIAL ";
@ -994,8 +1007,20 @@ void CellSlice::print_rec(std::ostream& os, int indent) const {
os << "x{" << as_bitslice().to_hex() << '}' << std::endl;
for (unsigned i = 0; i < size_refs(); i++) {
CellSlice cs{NoVm(), prefetch_ref(i)};
cs.print_rec(os, indent + 1);
if (!cs.print_rec(os, limit, indent + 1)) {
return false;
}
}
return true;
}
bool CellSlice::print_rec(std::ostream& os, int indent) const {
int limit = default_recursive_print_limit;
return print_rec(os, &limit, indent);
}
bool CellSlice::print_rec(int limit, std::ostream& os, int indent) const {
return print_rec(os, &limit, indent);
}
td::StringBuilder& operator<<(td::StringBuilder& sb, const CellSlice& cs) {

View file

@ -44,6 +44,7 @@ class CellSlice : public td::CntObject {
public:
static constexpr long long fetch_long_eof = (static_cast<unsigned long long>(-1LL) << 63);
static constexpr unsigned long long fetch_ulong_eof = (unsigned long long)-1LL;
enum { default_recursive_print_limit = 100 };
struct CellReadError {};
CellSlice(NoVm, Ref<Cell> cell_ref);
@ -129,6 +130,7 @@ class CellSlice : public td::CntObject {
const unsigned char* data() const {
return cell->get_data();
}
td::uint16 get_depth() const;
td::ConstBitPtr data_bits() const {
return td::ConstBitPtr{data(), (int)cur_pos()};
}
@ -252,7 +254,9 @@ class CellSlice : public td::CntObject {
bool contents_equal(const CellSlice& cs2) const;
void dump(std::ostream& os, int level = 0, bool endl = true) const;
void dump_hex(std::ostream& os, int mode = 0, bool endl = false) const;
void print_rec(std::ostream& os, int indent = 0) const;
bool print_rec(std::ostream& os, int indent = 0) const;
bool print_rec(std::ostream& os, int* limit, int indent = 0) const;
bool print_rec(int limit, std::ostream& os, int indent = 0) const;
void error() const {
throw CellReadError{};
}