1
0
Fork 0
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:
ton 2020-02-02 16:53:37 +04:00
parent acf16718e6
commit 53ec9684bd
70 changed files with 816 additions and 322 deletions

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
*/
#include "check-proof.h"
#include "block/block.h"
@ -219,7 +219,17 @@ td::Status check_account_proof(td::Slice proof, ton::BlockIdExt shard_blk, const
}
td::Result<AccountState::Info> AccountState::validate(ton::BlockIdExt ref_blk, block::StdAddress addr) const {
TRY_RESULT_PREFIX(root, vm::std_boc_deserialize(state.as_slice(), true), "cannot deserialize account state");
TRY_RESULT_PREFIX(true_root, vm::std_boc_deserialize(state.as_slice(), true), "cannot deserialize account state");
Ref<vm::Cell> root;
if (is_virtualized && true_root.not_null()) {
root = vm::MerkleProof::virtualize(true_root, 1);
if (root.is_null()) {
return td::Status::Error("account state proof is invalid");
}
} else {
root = true_root;
}
if (blk != ref_blk && ref_blk.id.seqno != ~0U) {
return td::Status::Error(PSLICE() << "obtained getAccountState() for a different reference block " << blk.to_str()
@ -241,6 +251,7 @@ td::Result<AccountState::Info> AccountState::validate(ton::BlockIdExt ref_blk, b
TRY_STATUS(block::check_account_proof(proof.as_slice(), shard_blk, addr, root, &res.last_trans_lt,
&res.last_trans_hash, &res.gen_utime, &res.gen_lt));
res.root = std::move(root);
res.true_root = std::move(true_root);
return res;
}

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
@ -44,10 +44,11 @@ struct AccountState {
td::BufferSlice shard_proof;
td::BufferSlice proof;
td::BufferSlice state;
bool is_virtualized{false};
struct Info {
td::Ref<vm::Cell> root;
ton::LogicalTime last_trans_lt = 0;
td::Ref<vm::Cell> root, true_root;
ton::LogicalTime last_trans_lt{0};
ton::Bits256 last_trans_hash;
ton::LogicalTime gen_lt{0};
td::uint32 gen_utime{0};

View file

@ -23,7 +23,7 @@
exception statement from your version. If you delete this exception statement
from all source files in the program, then also delete it here.
Copyright 2017-2019 Telegram Systems LLP
Copyright 2017-2020 Telegram Systems LLP
*/
#include "mc-config.h"
#include "block/block.h"
@ -752,8 +752,8 @@ Ref<McShardDescr> McShardDescr::from_block(Ref<vm::Cell> block_root, Ref<vm::Cel
return {};
}
// TODO: use a suitable vm::MerkleUpdate method here
vm::CellSlice cs(vm::NoVm(), rec.state_update);
if (cs.special_type() != vm::Cell::SpecialType::MerkleUpdate) {
vm::CellSlice cs(vm::NoVmSpec(), rec.state_update);
if (!cs.is_valid() || cs.special_type() != vm::Cell::SpecialType::MerkleUpdate) {
LOG(ERROR) << "state update in a block is not a Merkle update";
return {};
}
@ -870,7 +870,7 @@ bool ShardConfig::get_shard_hash_raw_from(vm::Dictionary& dict, vm::CellSlice& c
unsigned long long z = id.shard, m = std::numeric_limits<unsigned long long>::max();
int len = id.pfx_len();
while (true) {
cs.load(vm::NoVmOrd{}, leaf ? root : std::move(root));
cs.load(vm::NoVmOrd(), leaf ? root : std::move(root));
int t = (int)cs.fetch_ulong(1);
if (t < 0) {
return false; // throw DictError ?
@ -1108,7 +1108,7 @@ std::vector<ton::BlockId> ShardConfig::get_shard_hash_ids(
std::stack<std::pair<Ref<vm::Cell>, unsigned long long>> stack;
stack.emplace(cs_ref->prefetch_ref(), ton::shardIdAll);
while (!stack.empty()) {
vm::CellSlice cs{vm::NoVm{}, std::move(stack.top().first)};
vm::CellSlice cs{vm::NoVmOrd(), std::move(stack.top().first)};
unsigned long long shard = stack.top().second;
stack.pop();
int t = (int)cs.fetch_ulong(1);

View file

@ -965,6 +965,11 @@ x{F4B5} @Defop SUBDICTRPGET
x{F4B6} @Defop SUBDICTIRPGET
x{F4B7} @Defop SUBDICTURPGET
x{F4BC} @Defop DICTIGETJMPZ
x{F4BD} @Defop DICTUGETJMPZ
x{F4BE} @Defop DICTIGETEXECZ
x{F4BF} @Defop DICTUGETEXECZ
//
// blockchain-specific primitives
@ -1117,7 +1122,7 @@ variable @gvarcnt
@procdict dup @ swap null!
} : }END
forget @proclist forget @proccnt
{ }END <{ SETCP0 swap @procdictkeylen DICTPUSHCONST DICTIGETJMP 11 THROWARG }> } : }END>
{ }END <{ SETCP0 swap @procdictkeylen DICTPUSHCONST DICTIGETJMPZ 11 THROWARG }> } : }END>
{ }END> b> } : }END>c
{ }END>c <s } : }END>s

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
*/
#include "words.h"
@ -1007,8 +1007,8 @@ void interpret_store_end(vm::Stack& stack, bool special) {
void interpret_from_cell(vm::Stack& stack) {
auto cell = stack.pop_cell();
Ref<vm::CellSlice> cs{true};
if (!cs.unique_write().load(vm::NoVmOrd(), std::move(cell))) {
Ref<vm::CellSlice> cs{true, vm::NoVmOrd(), std::move(cell)};
if (!cs->is_valid()) {
throw IntError{"deserializing a special cell as ordinary"};
}
stack.push(cs);
@ -1117,7 +1117,10 @@ void interpret_fetch_ref(vm::Stack& stack, int mode) {
stack.push(std::move(cs));
}
if (mode & 1) {
Ref<vm::CellSlice> new_cs{true, vm::NoVm(), std::move(cell)};
Ref<vm::CellSlice> new_cs{true, vm::NoVmOrd(), std::move(cell)};
if (!new_cs->is_valid()) {
throw IntError{"cannot load ordinary cell"};
}
stack.push(std::move(new_cs));
} else {
stack.push_cell(std::move(cell));

View file

@ -39,3 +39,9 @@
int seqno() method_id {
return get_data().begin_parse().preload_uint(32);
}
int get_public_key() method_id {
var cs = get_data().begin_parse();
cs~load_uint(64);
return cs.preload_uint(256);
}

View file

@ -63,3 +63,9 @@ int processed?(int query_id) method_id {
(_, var found) = old_queries.udict_get?(64, query_id);
return found ? true : - (query_id <= last_cleaned);
}
int get_public_key() method_id {
var cs = get_data().begin_parse();
cs~load_uint(32 + 64);
return cs.preload_uint(256);
}

View file

@ -15,8 +15,8 @@ def? $2 { @' $2 } { "new-wallet" } cond constant file-base
// Create new advanced wallet; code adapted from `auto/wallet-code.fif`
<{ SETCP0 DUP IFNOTRET // return if recv_internal
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
DROP c4 PUSHCTR CTOS 32 PLDU // cnt
DUP 85143 INT EQUAL OVER 78748 INT EQUAL OR IFJMP:<{ // "seqno" and "get_public_key" get-methods
1 INT AND c4 PUSHCTR CTOS 32 LDU 256 PLDU CONDSEL // cnt or pubk
}>
INC 32 THROWIF // fail unless recv_external
9 PUSHPOW2 LDSLICEX DUP 32 LDU 32 LDU // signature in_msg msg_seqno valid_until cs

View file

@ -18,8 +18,8 @@ $3 "new-wallet" replace-if-null =: file-base
// Create new advanced wallet; code adapted from `auto/wallet3-code.fif`
<{ SETCP0 DUP IFNOTRET // return if recv_internal
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
DROP c4 PUSHCTR CTOS 32 PLDU // cnt
DUP 85143 INT EQUAL OVER 78748 INT EQUAL OR IFJMP:<{ // "seqno" and "get_public_key" get-methods
1 INT AND c4 PUSHCTR CTOS 32 LDU 32 LDU NIP 256 PLDU CONDSEL // cnt or pubk
}>
INC 32 THROWIF // fail unless recv_external
9 PUSHPOW2 LDSLICEX DUP 32 LDU 32 LDU 32 LDU // signature in_msg subwallet_id valid_until msg_seqno cs

View file

@ -15,8 +15,8 @@ def? $2 { @' $2 } { "new-wallet" } cond constant file-base
// Create new simple wallet
<{ SETCP0 DUP IFNOTRET // return if recv_internal
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
DROP c4 PUSHCTR CTOS 32 PLDU // cnt
DUP 85143 INT EQUAL OVER 78748 INT EQUAL OR IFJMP:<{ // "seqno" and "get_public_key" get-methods
1 INT AND c4 PUSHCTR CTOS 32 LDU 256 PLDU CONDSEL // cnt or pubk
}>
INC 32 THROWIF // fail unless recv_external
512 INT LDSLICEX DUP 32 PLDU // sign cs cnt

View file

@ -62,6 +62,12 @@ int seqno() method_id {
return get_data().begin_parse().preload_uint(32);
}
int get_public_key() method_id {
var cs = get_data().begin_parse();
cs~load_uint(32);
return cs.preload_uint(256);
}
int balance() method_id {
return restricted?() ? 0 : get_balance().first();
}

View file

@ -55,6 +55,12 @@ int seqno() method_id {
return get_data().begin_parse().preload_uint(32);
}
int get_public_key() method_id {
var cs = get_data().begin_parse();
cs~load_uint(32);
return cs.preload_uint(256);
}
int balance() method_id {
var ds = get_data().begin_parse().skip_bits(32 + 256);
var rdict = ds~load_dict();

View file

@ -45,6 +45,11 @@ int seqno() method_id {
return get_data().begin_parse().preload_uint(32);
}
int get_public_key() method_id {
var (seqno, public_key) = load_state();
return public_key;
}
cell create_init_state(int public_key) method_id {
return create_state(0, public_key);
}

View file

@ -29,3 +29,9 @@
int seqno() method_id {
return get_data().begin_parse().preload_uint(32);
}
int get_public_key() method_id {
var cs = get_data().begin_parse();
cs~load_uint(32);
return cs.preload_uint(256);
}

View file

@ -33,3 +33,9 @@
int seqno() method_id {
return get_data().begin_parse().preload_uint(32);
}
int get_public_key() method_id {
var cs = get_data().begin_parse();
cs~load_uint(64);
return cs.preload_uint(256);
}

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
*/
#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()};
}

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
@ -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();

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
*/
#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));

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
*/
#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

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
@ -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>

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
*/
#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));
}