Kagome
Polkadot Runtime Engine in C++17
instance_environment_factory.cpp
Go to the documentation of this file.
1 
7 
16 
17 namespace kagome::runtime::wavm {
18 
20  std::shared_ptr<storage::trie::TrieStorage> storage,
21  std::shared_ptr<storage::trie::TrieSerializer> serializer,
22  std::shared_ptr<CompartmentWrapper> compartment,
23  std::shared_ptr<ModuleParams> module_params,
24  std::shared_ptr<IntrinsicModule> intrinsic_module,
25  std::shared_ptr<host_api::HostApiFactory> host_api_factory,
26  std::shared_ptr<blockchain::BlockHeaderRepository> block_header_repo,
27  std::shared_ptr<storage::changes_trie::ChangesTracker> changes_tracker,
28  std::shared_ptr<kagome::runtime::SingleModuleCache> last_compiled_module,
29  std::shared_ptr<runtime::RuntimePropertiesCache> cache)
30  : storage_{std::move(storage)},
31  serializer_{std::move(serializer)},
32  compartment_{std::move(compartment)},
33  module_params_{std::move(module_params)},
34  intrinsic_module_{std::move(intrinsic_module)},
35  host_api_factory_{std::move(host_api_factory)},
36  block_header_repo_{std::move(block_header_repo)},
37  changes_tracker_{std::move(changes_tracker)},
38  last_compiled_module_{std::move(last_compiled_module)},
39  cache_(std::move(cache)) {
40  BOOST_ASSERT(storage_ != nullptr);
41  BOOST_ASSERT(serializer_ != nullptr);
42  BOOST_ASSERT(compartment_ != nullptr);
43  BOOST_ASSERT(module_params_ != nullptr);
44  BOOST_ASSERT(intrinsic_module_ != nullptr);
45  BOOST_ASSERT(host_api_factory_ != nullptr);
46  BOOST_ASSERT(block_header_repo_ != nullptr);
47  BOOST_ASSERT(changes_tracker_ != nullptr);
48  BOOST_ASSERT(last_compiled_module_ != nullptr);
49  BOOST_ASSERT(cache_ != nullptr);
50  }
51 
53  MemoryOrigin memory_origin,
54  WAVM::Runtime::Instance *runtime_instance,
55  std::shared_ptr<IntrinsicModuleInstance> intrinsic_instance) const {
56  auto new_storage_provider =
57  std::make_shared<TrieStorageProviderImpl>(storage_, serializer_);
58  auto core_factory =
59  std::make_shared<CoreApiFactoryImpl>(compartment_,
60  module_params_,
61  intrinsic_module_,
62  storage_,
64  shared_from_this(),
66  last_compiled_module_,
67  cache_);
68 
69  std::shared_ptr<MemoryProvider> memory_provider;
70  switch (memory_origin) {
71  case MemoryOrigin::EXTERNAL:
72  memory_provider =
73  std::make_shared<WavmExternalMemoryProvider>(intrinsic_instance);
74  break;
75  case MemoryOrigin::INTERNAL: {
76  auto *memory = WAVM::Runtime::getDefaultMemory(runtime_instance);
77  memory_provider = std::make_shared<WavmInternalMemoryProvider>(memory);
78  } break;
79  }
80  auto host_api = std::shared_ptr<host_api::HostApi>(host_api_factory_->make(
81  core_factory, memory_provider, new_storage_provider));
82 
83  return InstanceEnvironment{std::move(memory_provider),
84  std::move(new_storage_provider),
85  std::move(host_api),
86  {}};
87  }
88 
89 } // namespace kagome::runtime::wavm
std::shared_ptr< blockchain::BlockHeaderRepository > block_header_repo_
std::shared_ptr< storage::changes_trie::ChangesTracker > changes_tracker_
InstanceEnvironmentFactory(std::shared_ptr< storage::trie::TrieStorage > storage, std::shared_ptr< storage::trie::TrieSerializer > serializer, std::shared_ptr< CompartmentWrapper > compartment, std::shared_ptr< ModuleParams > module_params, std::shared_ptr< IntrinsicModule > intrinsic_module, std::shared_ptr< host_api::HostApiFactory > host_api_factory, std::shared_ptr< blockchain::BlockHeaderRepository > block_header_repo, std::shared_ptr< storage::changes_trie::ChangesTracker > changes_tracker, std::shared_ptr< SingleModuleCache > last_compiled_module, std::shared_ptr< RuntimePropertiesCache > cache)
std::shared_ptr< storage::trie::TrieStorage > storage_
std::shared_ptr< storage::trie::TrieSerializer > serializer_
std::shared_ptr< host_api::HostApiFactory > host_api_factory_