Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fetching mc config for runSmcMethod, fix caching in LS (#915) #916

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions validator/impl/liteserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void LiteQuery::start_up() {
});
return;
}
use_cache_ = !cache_.empty() && query_obj_->get_id() == lite_api::liteServer_runSmcMethod::ID;
use_cache_ = use_cache();
if (use_cache_) {
cache_key_ = td::sha256_bits256(query_);
td::actor::send_closure(
Expand All @@ -173,6 +173,22 @@ void LiteQuery::start_up() {
}
}

bool LiteQuery::use_cache() {
if (cache_.empty()) {
return false;
}
bool use = false;
lite_api::downcast_call(
*query_obj_,
td::overloaded(
[&](lite_api::liteServer_runSmcMethod& q) {
// wc=-1, seqno=-1 means "use latest mc block"
use = q.id_->workchain_ != masterchainId || q.id_->seqno_ != -1;
},
[&](auto& obj) { use = false; }));
return use;
}

void LiteQuery::perform() {
td::actor::send_closure(manager_, &ValidatorManager::add_lite_query_stats, query_obj_->get_id());
lite_api::downcast_call(
Expand Down Expand Up @@ -1245,8 +1261,24 @@ void LiteQuery::finish_getAccountState(td::BufferSlice shard_proof) {
return;
}
if (mode_ & 0x10000) {
finish_runSmcMethod(std::move(shard_proof), proof.move_as_ok(), std::move(acc_root), sstate.gen_utime,
sstate.gen_lt);
if (!mc_state_.is_null()) {
finish_runSmcMethod(std::move(shard_proof), proof.move_as_ok(), std::move(acc_root), sstate.gen_utime,
sstate.gen_lt);
return;
}
shard_proof_ = std::move(shard_proof);
proof_ = proof.move_as_ok();
set_continuation(
[&, base_blk_id = base_blk_id_, acc_root, utime = sstate.gen_utime, lt = sstate.gen_lt]() mutable -> void {
base_blk_id_ = base_blk_id; // It gets overridden by request_mc_block_data_state
finish_runSmcMethod(std::move(shard_proof_), std::move(proof_), std::move(acc_root), utime, lt);
});
td::optional<BlockIdExt> master_ref = state_->get_master_ref();
if (!master_ref) {
fatal_error("masterchain ref block is not available");
return;
}
request_mc_block_data_state(master_ref.value());
return;
}
td::BufferSlice data;
Expand Down
3 changes: 2 additions & 1 deletion validator/impl/liteserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class LiteQuery : public td::actor::Actor {
td::BufferSlice buffer_;
std::function<void()> continuation_;
bool cont_set_{false};
td::BufferSlice shard_proof_;
td::BufferSlice shard_proof_, proof_;
std::vector<Ref<vm::Cell>> roots_;
std::vector<Ref<td::CntObject>> aux_objs_;
std::vector<ton::BlockIdExt> blk_ids_;
Expand Down Expand Up @@ -98,6 +98,7 @@ class LiteQuery : public td::actor::Actor {
bool finish_query(td::BufferSlice result, bool skip_cache_update = false);
void alarm() override;
void start_up() override;
bool use_cache();
void perform();
void perform_getTime();
void perform_getVersion();
Expand Down
9 changes: 9 additions & 0 deletions validator/impl/shard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ td::Status ShardStateQ::init() {
" contains BlockId " + hdr_id.to_str() +
" different from the one originally required");
}
if (info.r1.master_ref.write().fetch_long(1)) {
BlockIdExt mc_id;
if (!block::tlb::t_ExtBlkRef.unpack(info.r1.master_ref, mc_id, nullptr)) {
return td::Status::Error(-668, "cannot unpack master_ref in shardchain state of "s + blkid.to_str());
}
master_ref = mc_id;
} else {
master_ref = {};
}
return td::Status::OK();
}

Expand Down
4 changes: 4 additions & 0 deletions validator/impl/shard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ShardStateQ : virtual public ShardState {
bool before_split_{false};
bool fake_split_{false};
bool fake_merge_{false};
td::optional<BlockIdExt> master_ref;

protected:
friend class Ref<ShardStateQ>;
Expand Down Expand Up @@ -80,6 +81,9 @@ class ShardStateQ : virtual public ShardState {
LogicalTime get_logical_time() const override {
return lt;
}
td::optional<BlockIdExt> get_master_ref() const override {
return master_ref;
}
td::Status validate_deep() const override;
ShardStateQ* make_copy() const override;
td::Result<Ref<MessageQueue>> message_queue() const override;
Expand Down
1 change: 1 addition & 0 deletions validator/interfaces/shard.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ShardState : public td::CntObject {
virtual BlockIdExt get_block_id() const = 0;
virtual RootHash root_hash() const = 0;
virtual td::Ref<vm::Cell> root_cell() const = 0;
virtual td::optional<BlockIdExt> get_master_ref() const = 0;

virtual td::Status validate_deep() const = 0;

Expand Down
Loading