mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
updated liteserver
- new methods for liteserver/liteclient - added ADNL/DHT client-only work mode - fixed crash in ADNL
This commit is contained in:
parent
acf16718e6
commit
53ec9684bd
70 changed files with 816 additions and 322 deletions
|
@ -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
|
||||
*/
|
||||
#include "vm/cells/CellBuilder.h"
|
||||
|
||||
|
@ -460,6 +460,16 @@ bool CellBuilder::append_cellslice_chk(Ref<CellSlice> cs_ref, unsigned size_ext)
|
|||
return cs_ref.not_null() && append_cellslice_chk(*cs_ref, size_ext);
|
||||
}
|
||||
|
||||
CellSlice CellSlice::clone() const {
|
||||
CellBuilder cb;
|
||||
Ref<Cell> cell;
|
||||
if (cb.append_cellslice_bool(*this) && cb.finalize_to(cell)) {
|
||||
return CellSlice{NoVmOrd(), std::move(cell)};
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
bool CellBuilder::append_bitstring(const td::BitString& bs) {
|
||||
return store_bits_bool(bs.cbits(), bs.size());
|
||||
}
|
||||
|
@ -536,11 +546,11 @@ CellBuilder* CellBuilder::make_copy() const {
|
|||
return c;
|
||||
}
|
||||
|
||||
CellSlice CellBuilder::as_cellslice() const& {
|
||||
CellSlice CellBuilder::as_cellslice() const & {
|
||||
return CellSlice{finalize_copy()};
|
||||
}
|
||||
|
||||
Ref<CellSlice> CellBuilder::as_cellslice_ref() const& {
|
||||
Ref<CellSlice> CellBuilder::as_cellslice_ref() const & {
|
||||
return Ref<CellSlice>{true, finalize_copy()};
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -275,6 +275,7 @@ class CellSlice : public td::CntObject {
|
|||
offs = std::min(offs, size());
|
||||
return CellSlice{*this, size() - offs, size_refs(), offs, 0};
|
||||
}
|
||||
CellSlice clone() const;
|
||||
|
||||
private:
|
||||
void init_bits_refs();
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
#include "vm/dict.h"
|
||||
#include "vm/cells.h"
|
||||
|
@ -179,7 +179,7 @@ bool DictionaryBase::append_dict_to_bool(CellBuilder& cb) && {
|
|||
return cb.store_maybe_ref(std::move(root_cell));
|
||||
}
|
||||
|
||||
bool DictionaryBase::append_dict_to_bool(CellBuilder& cb) const& {
|
||||
bool DictionaryBase::append_dict_to_bool(CellBuilder& cb) const & {
|
||||
return is_valid() && cb.store_maybe_ref(root_cell);
|
||||
}
|
||||
|
||||
|
@ -2240,7 +2240,7 @@ Ref<CellSlice> AugmentedDictionary::extract_root() && {
|
|||
return std::move(root);
|
||||
}
|
||||
|
||||
bool AugmentedDictionary::append_dict_to_bool(CellBuilder& cb) const& {
|
||||
bool AugmentedDictionary::append_dict_to_bool(CellBuilder& cb) const & {
|
||||
if (!is_valid()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2535,7 +2535,7 @@ bool AugmentedDictionary::set(td::ConstBitPtr key, int key_len, const CellSlice&
|
|||
}
|
||||
auto res = dict_set(get_root_cell(), key, key_len, value, mode);
|
||||
if (res.second) {
|
||||
//vm::CellSlice cs{vm::NoVm{}, res.first};
|
||||
//vm::CellSlice cs{vm::NoVmOrd(), res.first};
|
||||
//std::cerr << "new augmented dictionary root is:\n";
|
||||
//cs.print_rec(std::cerr);
|
||||
set_root_cell(std::move(res.first));
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
#include <functional>
|
||||
#include "vm/log.h"
|
||||
|
@ -210,7 +210,7 @@ int exec_dict_get(VmState* st, unsigned args) {
|
|||
BitSlice key;
|
||||
unsigned char buffer[Dictionary::max_key_bytes];
|
||||
if (args & 4) {
|
||||
key = dict.integer_key(stack.pop_int(), n, !(args & 2), buffer, true);
|
||||
key = dict.integer_key(stack.pop_int_finite(), n, !(args & 2), buffer, true);
|
||||
if (!key.is_valid()) {
|
||||
stack.push_smallint(0);
|
||||
return 0;
|
||||
|
@ -250,7 +250,7 @@ int exec_dict_get_optref(VmState* st, unsigned args) {
|
|||
BitSlice key;
|
||||
unsigned char buffer[Dictionary::max_key_bytes];
|
||||
if (args & 2) {
|
||||
key = dict.integer_key(stack.pop_int(), n, !(args & 1), buffer, true);
|
||||
key = dict.integer_key(stack.pop_int_finite(), n, !(args & 1), buffer, true);
|
||||
if (!key.is_valid()) {
|
||||
stack.push_null();
|
||||
return 0;
|
||||
|
@ -377,7 +377,7 @@ int exec_dict_delete(VmState* st, unsigned args) {
|
|||
BitSlice key;
|
||||
unsigned char buffer[Dictionary::max_key_bytes];
|
||||
if (args & 2) {
|
||||
key = dict.integer_key(stack.pop_int(), n, !(args & 1), buffer);
|
||||
key = dict.integer_key(stack.pop_int_finite(), n, !(args & 1), buffer);
|
||||
if (!key.is_valid()) {
|
||||
push_dict(stack, std::move(dict));
|
||||
stack.push_smallint(0);
|
||||
|
@ -404,7 +404,7 @@ int exec_dict_deleteget(VmState* st, unsigned args) {
|
|||
BitSlice key;
|
||||
unsigned char buffer[Dictionary::max_key_bytes];
|
||||
if (args & 4) {
|
||||
key = dict.integer_key(stack.pop_int(), n, !(args & 2), buffer);
|
||||
key = dict.integer_key(stack.pop_int_finite(), n, !(args & 2), buffer);
|
||||
if (!key.is_valid()) {
|
||||
push_dict(stack, std::move(dict));
|
||||
stack.push_smallint(0);
|
||||
|
@ -588,23 +588,29 @@ int exec_pfx_dict_delete(VmState* st) {
|
|||
|
||||
int exec_dict_get_exec(VmState* st, unsigned args) {
|
||||
Stack& stack = st->get_stack();
|
||||
VM_LOG(st) << "execute DICT" << (args & 1 ? 'U' : 'I') << "GET" << (args & 2 ? "EXEC\n" : "JMP\n");
|
||||
VM_LOG(st) << "execute DICT" << (args & 1 ? 'U' : 'I') << "GET" << (args & 2 ? "EXEC" : "JMP")
|
||||
<< (args & 4 ? "Z" : "");
|
||||
stack.check_underflow(3);
|
||||
int n = stack.pop_smallint_range(Dictionary::max_key_bits);
|
||||
Dictionary dict{stack.pop_maybe_cell(), n};
|
||||
unsigned char buffer[Dictionary::max_key_bytes];
|
||||
dict.integer_key_simple(stack.pop_int(), n, !(args & 1), td::BitPtr{buffer});
|
||||
auto value = dict.lookup(td::BitPtr{buffer}, n);
|
||||
if (value.not_null()) {
|
||||
Ref<OrdCont> cont{true, std::move(value), st->get_cp()};
|
||||
return (args & 2) ? st->call(std::move(cont)) : st->jump(std::move(cont));
|
||||
} else {
|
||||
return 0;
|
||||
auto idx = stack.pop_int_finite();
|
||||
if (dict.integer_key_simple(idx, n, !(args & 1), td::BitPtr{buffer}, true)) {
|
||||
auto value = dict.lookup(td::BitPtr{buffer}, n);
|
||||
if (value.not_null()) {
|
||||
Ref<OrdCont> cont{true, std::move(value), st->get_cp()};
|
||||
return (args & 2) ? st->call(std::move(cont)) : st->jump(std::move(cont));
|
||||
}
|
||||
}
|
||||
// key not found or out of range
|
||||
if (args & 4) {
|
||||
stack.push_int(std::move(idx));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string dump_dict_get_exec(CellSlice& cs, unsigned args) {
|
||||
return std::string{"DICT"} + (args & 1 ? 'U' : 'I') + "GET" + (args & 2 ? "EXEC" : "JMP");
|
||||
return std::string{"DICT"} + (args & 1 ? 'U' : 'I') + "GET" + (args & 2 ? "EXEC" : "JMP") + (args & 4 ? "Z" : "");
|
||||
}
|
||||
|
||||
int exec_push_const_dict(VmState* st, CellSlice& cs, unsigned args, int pfx_bits) {
|
||||
|
@ -720,7 +726,7 @@ int exec_subdict_get(VmState* st, unsigned args) {
|
|||
BitSlice key;
|
||||
unsigned char buffer[Dictionary::max_key_bytes];
|
||||
if (args & 2) {
|
||||
key = dict.integer_key(stack.pop_int(), k, !(args & 1), buffer, true);
|
||||
key = dict.integer_key(stack.pop_int_finite(), k, !(args & 1), buffer, true);
|
||||
} else {
|
||||
key = stack.pop_cellslice()->prefetch_bits(k);
|
||||
}
|
||||
|
@ -805,7 +811,8 @@ void register_dictionary_ops(OpcodeTable& cp0) {
|
|||
exec_const_pfx_dict_switch, compute_len_push_const_dict))
|
||||
.insert(OpcodeInstr::mkfixedrange(0xf4b1, 0xf4b4, 16, 3, std::bind(dump_subdictop2, _2, "GET"), exec_subdict_get))
|
||||
.insert(
|
||||
OpcodeInstr::mkfixedrange(0xf4b5, 0xf4b8, 16, 3, std::bind(dump_subdictop2, _2, "RPGET"), exec_subdict_get));
|
||||
OpcodeInstr::mkfixedrange(0xf4b5, 0xf4b8, 16, 3, std::bind(dump_subdictop2, _2, "RPGET"), exec_subdict_get))
|
||||
.insert(OpcodeInstr::mkfixed(0xf4bc >> 2, 14, 2, dump_dict_get_exec, exec_dict_get_exec));
|
||||
}
|
||||
|
||||
} // namespace vm
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -33,6 +33,12 @@ struct VmLog {
|
|||
td::LogOptions log_options{td::log_options};
|
||||
enum { DumpStack = 2 };
|
||||
int log_mask{1};
|
||||
static VmLog Null() {
|
||||
VmLog res;
|
||||
res.log_options.level = 0;
|
||||
res.log_mask = 0;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
template <class State>
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
#include "vm/stack.hpp"
|
||||
#include "vm/continuation.h"
|
||||
|
@ -824,7 +824,7 @@ bool StackEntry::deserialize(CellSlice& cs, int mode) {
|
|||
return false;
|
||||
}
|
||||
} else if (n == 1) {
|
||||
return cs.have_refs() && t[0].deserialize(cs.fetch_ref(), mode);
|
||||
return cs.have_refs() && t[0].deserialize(cs.fetch_ref(), mode) && set(t_tuple, std::move(tuple));
|
||||
}
|
||||
return set(t_tuple, std::move(tuple));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue