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

updated smartcontract code

updated lite-client and configuration smartcontract
updated tonlib code
This commit is contained in:
ton 2019-09-16 12:06:04 +04:00
parent 8e5bd938aa
commit bce33f588a
46 changed files with 677 additions and 299 deletions

View file

@ -1443,19 +1443,32 @@ bool Collator::fetch_config_params() {
{
// compute compute_phase_cfg / storage_phase_cfg
auto cell = config_->get_config_param(is_masterchain() ? 20 : 21);
block::gen::GasLimitsPrices::Record rec;
if (cell.is_null() || !tlb::unpack_cell(std::move(cell), rec)) {
if (cell.is_null()) {
return fatal_error("cannot fetch current gas prices and limits from masterchain configuration");
}
compute_phase_cfg_.gas_limit = rec.gas_limit;
compute_phase_cfg_.gas_credit = rec.gas_credit;
compute_phase_cfg_.gas_price = rec.gas_price;
auto f = [self = this](const auto& r, td::uint64 spec_limit) {
self->compute_phase_cfg_.gas_limit = r.gas_limit;
self->compute_phase_cfg_.special_gas_limit = spec_limit;
self->compute_phase_cfg_.gas_credit = r.gas_credit;
self->compute_phase_cfg_.gas_price = r.gas_price;
self->storage_phase_cfg_.freeze_due_limit = td::RefInt256{true, r.freeze_due_limit};
self->storage_phase_cfg_.delete_due_limit = td::RefInt256{true, r.delete_due_limit};
};
block::gen::GasLimitsPrices::Record_gas_prices_ext rec;
if (tlb::unpack_cell(cell, rec)) {
f(rec, rec.special_gas_limit);
} else {
block::gen::GasLimitsPrices::Record_gas_prices rec0;
if (tlb::unpack_cell(std::move(cell), rec0)) {
f(rec0, rec0.gas_limit);
} else {
return fatal_error("cannot unpack current gas prices and limits from masterchain configuration");
}
}
compute_phase_cfg_.compute_threshold();
compute_phase_cfg_.block_rand_seed = rand_seed_;
compute_phase_cfg_.libraries = std::make_unique<vm::Dictionary>(config_->get_libraries_root(), 256);
compute_phase_cfg_.global_config = config_->get_root_cell();
storage_phase_cfg_.freeze_due_limit = td::RefInt256{true, rec.freeze_due_limit};
storage_phase_cfg_.delete_due_limit = td::RefInt256{true, rec.delete_due_limit};
}
{
// compute action_phase_cfg

View file

@ -118,7 +118,10 @@ void LiteQuery::start_up() {
td::overloaded(
[&](lite_api::liteServer_getTime& q) { this->perform_getTime(); },
[&](lite_api::liteServer_getVersion& q) { this->perform_getVersion(); },
[&](lite_api::liteServer_getMasterchainInfo& q) { this->perform_getMasterchainInfo(); },
[&](lite_api::liteServer_getMasterchainInfo& q) { this->perform_getMasterchainInfo(-1); },
[&](lite_api::liteServer_getMasterchainInfoExt& q) {
this->perform_getMasterchainInfo(q.mode_ & 0x7fffffff);
},
[&](lite_api::liteServer_getBlock& q) { this->perform_getBlock(ton::create_block_id(q.id_)); },
[&](lite_api::liteServer_getBlockHeader& q) {
this->perform_getBlockHeader(ton::create_block_id(q.id_), q.mode_);
@ -181,22 +184,27 @@ void LiteQuery::perform_getVersion() {
finish_query(std::move(b));
}
void LiteQuery::perform_getMasterchainInfo() {
LOG(INFO) << "started a getMasterchainInfo() liteserver query";
void LiteQuery::perform_getMasterchainInfo(int mode) {
LOG(INFO) << "started a getMasterchainInfo(" << mode << ") liteserver query";
if (mode > 0) {
fatal_error("unsupported getMasterchainInfo mode");
return;
}
td::actor::send_closure_later(
manager_, &ton::validator::ValidatorManager::get_top_masterchain_state_block,
[Self = actor_id(this)](td::Result<std::pair<Ref<ton::validator::MasterchainState>, BlockIdExt>> res)->void {
[ Self = actor_id(this), mode ](td::Result<std::pair<Ref<ton::validator::MasterchainState>, BlockIdExt>> res) {
if (res.is_error()) {
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
} else {
auto pair = res.move_as_ok();
td::actor::send_closure_later(Self, &LiteQuery::continue_getMasterchainInfo, std::move(pair.first),
pair.second);
pair.second, mode);
}
});
}
void LiteQuery::continue_getMasterchainInfo(Ref<ton::validator::MasterchainState> mc_state, BlockIdExt blkid) {
void LiteQuery::continue_getMasterchainInfo(Ref<ton::validator::MasterchainState> mc_state, BlockIdExt blkid,
int mode) {
LOG(INFO) << "obtained data for getMasterchainInfo() : last block = " << blkid.to_str();
auto mc_state_q = Ref<ton::validator::MasterchainStateQ>(std::move(mc_state));
if (mc_state_q.is_null()) {
@ -206,8 +214,12 @@ void LiteQuery::continue_getMasterchainInfo(Ref<ton::validator::MasterchainState
auto zerostate_id = mc_state_q->get_zerostate_id();
auto zs_tl = create_tl_object<lite_api::tonNode_zeroStateIdExt>(zerostate_id.workchain, zerostate_id.root_hash,
zerostate_id.file_hash);
auto b = ton::create_serialize_tl_object<ton::lite_api::liteServer_masterchainInfo>(
ton::create_tl_lite_block_id(blkid), mc_state_q->root_hash(), std::move(zs_tl));
td::int32 now = static_cast<td::int32>(std::time(nullptr));
auto b = (mode == -1) ? ton::create_serialize_tl_object<ton::lite_api::liteServer_masterchainInfo>(
ton::create_tl_lite_block_id(blkid), mc_state_q->root_hash(), std::move(zs_tl))
: ton::create_serialize_tl_object<ton::lite_api::liteServer_masterchainInfoExt>(
mode, ls_version, ls_capabilities, ton::create_tl_lite_block_id(blkid),
mc_state_q->get_unix_time(), now, mc_state_q->root_hash(), std::move(zs_tl));
finish_query(std::move(b));
}

View file

@ -57,8 +57,11 @@ class LiteQuery : public td::actor::Actor {
std::unique_ptr<block::BlockProofChain> chain_;
public:
enum { default_timeout_msec = 4500 }; // 4.5 seconds
enum { ls_version = 0x101, ls_capabilities = 1 }; // version 1.1; +1 = build block proof chains
enum { default_timeout_msec = 4500 }; // 4.5 seconds
enum {
ls_version = 0x101,
ls_capabilities = 3
}; // version 1.1; +1 = build block proof chains, +2 = masterchainInfoExt
LiteQuery(td::BufferSlice data, td::actor::ActorId<ton::validator::ValidatorManager> manager,
td::Promise<td::BufferSlice> promise);
static void run_query(td::BufferSlice data, td::actor::ActorId<ton::validator::ValidatorManager> manager,
@ -75,8 +78,8 @@ class LiteQuery : public td::actor::Actor {
void start_up() override;
void perform_getTime();
void perform_getVersion();
void perform_getMasterchainInfo();
void continue_getMasterchainInfo(Ref<MasterchainState> mc_state, BlockIdExt blkid);
void perform_getMasterchainInfo(int mode);
void continue_getMasterchainInfo(Ref<MasterchainState> mc_state, BlockIdExt blkid, int mode);
void perform_getBlock(BlockIdExt blkid);
void continue_getBlock(BlockIdExt blkid, Ref<BlockData> block);
void perform_getBlockHeader(BlockIdExt blkid, int mode);

View file

@ -255,7 +255,7 @@ void ValidateQuery::start_up() {
LOG(DEBUG) << "sending wait_block_state() query #" << i << " for " << prev_blocks[i].to_str() << " to Manager";
++pending;
td::actor::send_closure_later(manager, &ValidatorManager::wait_block_state_short, prev_blocks[i], priority(),
timeout, [self = get_self(), i](td::Result<Ref<ShardState>> res) -> void {
timeout, [ self = get_self(), i ](td::Result<Ref<ShardState>> res)->void {
LOG(DEBUG) << "got answer to wait_block_state_short query #" << i;
td::actor::send_closure_later(
std::move(self), &ValidateQuery::after_get_shard_state, i, std::move(res));
@ -269,16 +269,16 @@ void ValidateQuery::start_up() {
// 5. request masterchain state referred to in the block
if (!is_masterchain()) {
++pending;
td::actor::send_closure_later(manager, &ValidatorManager::wait_block_state_short, mc_blkid_, priority(), timeout,
[self = get_self()](td::Result<Ref<ShardState>> res) {
td::actor::send_closure_later(manager, &ValidatorManager::wait_block_state_short, mc_blkid_, priority(),
timeout, [self = get_self()](td::Result<Ref<ShardState>> res) {
LOG(DEBUG) << "got answer to wait_block_state() query for masterchain block";
td::actor::send_closure_later(std::move(self), &ValidateQuery::after_get_mc_state,
std::move(res));
});
// 5.1. request corresponding block handle
++pending;
td::actor::send_closure_later(manager, &ValidatorManager::get_block_handle, mc_blkid_, true,
[self = get_self()](td::Result<BlockHandle> res) {
td::actor::send_closure_later(manager, &ValidatorManager::get_block_handle, mc_blkid_,
true, [self = get_self()](td::Result<BlockHandle> res) {
LOG(DEBUG) << "got answer to get_block_handle() query for masterchain block";
td::actor::send_closure_later(std::move(self), &ValidateQuery::got_mc_handle,
std::move(res));
@ -722,19 +722,32 @@ bool ValidateQuery::fetch_config_params() {
{
// compute compute_phase_cfg / storage_phase_cfg
auto cell = config_->get_config_param(is_masterchain() ? 20 : 21);
block::gen::GasLimitsPrices::Record rec;
if (cell.is_null() || !tlb::unpack_cell(std::move(cell), rec)) {
if (cell.is_null()) {
return fatal_error("cannot fetch current gas prices and limits from masterchain configuration");
}
compute_phase_cfg_.gas_limit = rec.gas_limit;
compute_phase_cfg_.gas_credit = rec.gas_credit;
compute_phase_cfg_.gas_price = rec.gas_price;
auto f = [self = this](const auto& r, td::uint64 spec_limit) {
self->compute_phase_cfg_.gas_limit = r.gas_limit;
self->compute_phase_cfg_.special_gas_limit = spec_limit;
self->compute_phase_cfg_.gas_credit = r.gas_credit;
self->compute_phase_cfg_.gas_price = r.gas_price;
self->storage_phase_cfg_.freeze_due_limit = td::RefInt256{true, r.freeze_due_limit};
self->storage_phase_cfg_.delete_due_limit = td::RefInt256{true, r.delete_due_limit};
};
block::gen::GasLimitsPrices::Record_gas_prices_ext rec;
if (tlb::unpack_cell(cell, rec)) {
f(rec, rec.special_gas_limit);
} else {
block::gen::GasLimitsPrices::Record_gas_prices rec0;
if (tlb::unpack_cell(std::move(cell), rec0)) {
f(rec0, rec0.gas_limit);
} else {
return fatal_error("cannot unpack current gas prices and limits from masterchain configuration");
}
}
compute_phase_cfg_.compute_threshold();
compute_phase_cfg_.block_rand_seed = rand_seed_;
compute_phase_cfg_.libraries = std::make_unique<vm::Dictionary>(config_->get_libraries_root(), 256);
compute_phase_cfg_.global_config = config_->get_root_cell();
storage_phase_cfg_.freeze_due_limit = td::RefInt256{true, rec.freeze_due_limit};
storage_phase_cfg_.delete_due_limit = td::RefInt256{true, rec.delete_due_limit};
}
{
// compute action_phase_cfg
@ -1167,7 +1180,7 @@ bool ValidateQuery::request_neighbor_queues() {
LOG(DEBUG) << "neighbor #" << i << " : " << descr.blk_.to_str();
++pending;
send_closure_later(manager, &ValidatorManager::wait_block_message_queue_short, descr.blk_, priority(), timeout,
[self = get_self(), i](td::Result<Ref<MessageQueue>> res) {
[ self = get_self(), i ](td::Result<Ref<MessageQueue>> res) {
td::actor::send_closure(std::move(self), &ValidateQuery::got_neighbor_out_queue, i,
std::move(res));
});
@ -1285,13 +1298,12 @@ bool ValidateQuery::request_aux_mc_state(BlockSeqno seqno, Ref<MasterchainStateQ
CHECK(blkid.is_valid_ext() && blkid.is_masterchain());
LOG(DEBUG) << "sending auxiliary wait_block_state() query for " << blkid.to_str() << " to Manager";
++pending;
td::actor::send_closure_later(manager, &ValidatorManager::wait_block_state_short, blkid, priority(), timeout,
[self = get_self(), blkid](td::Result<Ref<ShardState>> res) {
LOG(DEBUG) << "got answer to wait_block_state query for " << blkid.to_str();
td::actor::send_closure_later(std::move(self),
&ValidateQuery::after_get_aux_shard_state, blkid,
std::move(res));
});
td::actor::send_closure_later(manager, &ValidatorManager::wait_block_state_short, blkid, priority(), timeout, [
self = get_self(), blkid
](td::Result<Ref<ShardState>> res) {
LOG(DEBUG) << "got answer to wait_block_state query for " << blkid.to_str();
td::actor::send_closure_later(std::move(self), &ValidateQuery::after_get_aux_shard_state, blkid, std::move(res));
});
state.clear();
return true;
}
@ -1627,8 +1639,8 @@ bool ValidateQuery::check_shard_layout() {
WorkchainId wc_id{ton::workchainInvalid};
Ref<block::WorkchainInfo> wc_info;
if (!new_shard_conf_->process_sibling_shard_hashes([self = this, &wc_set, &wc_id, &wc_info, &ccvc](
block::McShardHash& cur, const block::McShardHash* sibling) {
if (!new_shard_conf_->process_sibling_shard_hashes([ self = this, &wc_set, &wc_id, &wc_info, &ccvc ](
block::McShardHash & cur, const block::McShardHash* sibling) {
if (!cur.is_valid()) {
return -2;
}
@ -4619,8 +4631,8 @@ bool ValidateQuery::check_one_library_update(td::ConstBitPtr key, Ref<vm::CellSl
old_publishers = std::make_unique<vm::Dictionary>(256);
}
if (!old_publishers->scan_diff(*new_publishers,
[this, lib_key = key](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val,
Ref<vm::CellSlice> new_val) {
[ this, lib_key = key ](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val,
Ref<vm::CellSlice> new_val) {
CHECK(key_len == 256);
if (old_val.not_null() && !old_val->empty_ext()) {
return false;