Kagome
Polkadot Runtime Engine in C++17
runtime_environment_factory.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_RUNTIME_RUNTIME_ENVIRONMENT_FACTORY_HPP
7 #define KAGOME_CORE_RUNTIME_RUNTIME_ENVIRONMENT_FACTORY_HPP
8 
10 #include "common/buffer.hpp"
11 #include "host_api/host_api.hpp"
13 #include "log/logger.hpp"
14 #include "outcome/outcome.hpp"
15 #include "primitives/version.hpp"
20 #include "scale/scale.hpp"
22 
23 namespace kagome::runtime {
24 
26  public:
27  RuntimeEnvironment(std::shared_ptr<ModuleInstance> module_instance,
28  std::shared_ptr<const MemoryProvider> memory_provider,
29  std::shared_ptr<TrieStorageProvider> storage_provider,
30  primitives::BlockInfo blockchain_state);
31 
32  const std::shared_ptr<ModuleInstance> module_instance;
33  const std::shared_ptr<const MemoryProvider> memory_provider;
34  const std::shared_ptr<TrieStorageProvider> storage_provider;
36  };
37 
39  : public std::enable_shared_from_this<RuntimeEnvironmentFactory> {
40  public:
41  enum class Error {
42  PARENT_FACTORY_EXPIRED = 1,
43  ABSENT_BLOCK,
44  ABSENT_HEAP_BASE,
45  FAILED_TO_SET_STORAGE_STATE
46  };
48 
50  std::shared_ptr<const runtime::RuntimeCodeProvider> code_provider,
51  std::shared_ptr<ModuleRepository> module_repo,
52  std::shared_ptr<const blockchain::BlockHeaderRepository> header_repo);
53 
54  virtual ~RuntimeEnvironmentFactory() = default;
55 
66  [[nodiscard]] virtual std::unique_ptr<RuntimeEnvironmentTemplate> start(
67  const primitives::BlockInfo &blockchain_state,
68  const storage::trie::RootHash &storage_state) const;
69 
77  [[nodiscard]] virtual outcome::result<
78  std::unique_ptr<RuntimeEnvironmentTemplate>>
79  start(const primitives::BlockHash &blockchain_state) const;
80 
87  [[nodiscard]] virtual outcome::result<
88  std::unique_ptr<RuntimeEnvironmentTemplate>>
89  start() const;
90 
91  private:
92  std::shared_ptr<const runtime::RuntimeCodeProvider> code_provider_;
93  std::shared_ptr<ModuleRepository> module_repo_;
94  std::shared_ptr<const blockchain::BlockHeaderRepository> header_repo_;
96  };
97 
99  public:
101  std::weak_ptr<const RuntimeEnvironmentFactory> parent_factory_,
102  const primitives::BlockInfo &blockchain_state,
103  const storage::trie::RootHash &storage_state);
104 
105  virtual ~RuntimeEnvironmentTemplate() = default;
106 
107  [[nodiscard]] virtual RuntimeEnvironmentTemplate &persistent();
108 
109  [[nodiscard]] virtual outcome::result<std::unique_ptr<RuntimeEnvironment>>
110  make();
111 
112  private:
114 
115  // need to store separately from
116  // blockchain state because, for example, when we're in
117  // process of producing a block, there is no particular
118  // storage state associated with the block
120 
121  std::weak_ptr<const RuntimeEnvironmentFactory> parent_factory_;
122  bool persistent_{false};
123  };
124 
125 } // namespace kagome::runtime
126 
128 
129 #endif // KAGOME_CORE_RUNTIME_RUNTIME_ENVIRONMENT_FACTORY_HPP
OUTCOME_HPP_DECLARE_ERROR(kagome::runtime, RuntimeEnvironmentFactory::Error)
const std::shared_ptr< const MemoryProvider > memory_provider
const std::shared_ptr< TrieStorageProvider > storage_provider
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
RuntimeEnvironment(std::shared_ptr< ModuleInstance > module_instance, std::shared_ptr< const MemoryProvider > memory_provider, std::shared_ptr< TrieStorageProvider > storage_provider, primitives::BlockInfo blockchain_state)
std::shared_ptr< const blockchain::BlockHeaderRepository > header_repo_
std::shared_ptr< const runtime::RuntimeCodeProvider > code_provider_
std::shared_ptr< ModuleRepository > module_repo_
const std::shared_ptr< ModuleInstance > module_instance