mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	Merge pull request #916 from ton-blockchain/testnet
Fix fetching mc config for runSmcMethod, fix caching in LS (#915)
This commit is contained in:
		
						commit
						692211fe91
					
				
					 5 changed files with 51 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -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(
 | 
			
		||||
| 
						 | 
				
			
			@ -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(
 | 
			
		||||
| 
						 | 
				
			
			@ -1245,10 +1261,26 @@ void LiteQuery::finish_getAccountState(td::BufferSlice shard_proof) {
 | 
			
		|||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  if (mode_ & 0x10000) {
 | 
			
		||||
    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;
 | 
			
		||||
  if (acc_root.not_null()) {
 | 
			
		||||
    if (mode_ & 0x40000000) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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_;
 | 
			
		||||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>;
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue