Decouple the Spring app from runtime invocations. This PR showcases a variant of this decoupling using an explicit Context object to pass to the runtime builder, in which object all necessary dependencies for the host API endpoints are contained, thus granting the caller the ability to define all interactions from the runtime to the outside world through the behaviour of these dependencies.
The main goal of this MWE is to execute the first block in Kusama without ever starting the Spring app (i.e. in isolation). In more practical terms: to rewrite the previously existing BlockExecutorTest, and the new variant can be found in BlockExecutorIsolatedTest. The diff between the two tests is the starting point for grasping all the changes.
The bulk of refactoring is isolated in the package com.limechain.runtime.research.hybrid, where I've copied a lot of existing classes in an isolated environment and made changes on the copies, since applying changes in the already existing production classes quickly proved to be non-viable for the purpose of achieving a MWE.
Breakdown on the main changes within com.limechain.runtime.research.hybrid:
org.wasmer.Memory and FreeingBumpHeapAllocator have been put behind interfaces;
TrieAccessors are now injected the TrieStorage dependency on construction;
regarding the host api:
an Endpoint enumeration of all host api endpoints has been introduced, holding "just data", i.e. the signatures of the host api endpoints;
a HostApiImpl class is introduced to explicitly hold implementations of the endpoints and to simplify creation of ImportObjects exhaustively;
Runtime and RuntimeBuilder have been renamed to WasmRuntimeInstace and WasmRuntimeInstanceBuilder (names are WIP) and now obtain an explicit Context object on construction;
Other notable changes (outside the hybrid package) which were necessary to achieve this decoupling:
remove the BlockState field of TrieStorage, as it breaks separation of concerns;
TrieStorage is no longer a static singleton instance, as it is an implicit member of the Context (through the TrieAccessor);
[SIDE FIX / QUESTIONABLE] The runtime builder is now used for the runtimeVersionV1 endpoint instead of manual instantiation. More details at this commit: 21547d7005434d58ac867b4bca050219a99987fc.
Description
Decouple the Spring app from runtime invocations. This PR showcases a variant of this decoupling using an explicit
Context
object to pass to the runtime builder, in which object all necessary dependencies for the host API endpoints are contained, thus granting the caller the ability to define all interactions from the runtime to the outside world through the behaviour of these dependencies.The main goal of this MWE is to execute the first block in Kusama without ever starting the Spring app (i.e. in isolation). In more practical terms: to rewrite the previously existing
BlockExecutorTest
, and the new variant can be found in BlockExecutorIsolatedTest. The diff between the two tests is the starting point for grasping all the changes.The bulk of refactoring is isolated in the package
com.limechain.runtime.research.hybrid
, where I've copied a lot of existing classes in an isolated environment and made changes on the copies, since applying changes in the already existing production classes quickly proved to be non-viable for the purpose of achieving a MWE.Breakdown on the main changes within
com.limechain.runtime.research.hybrid
:org.wasmer.Memory
andFreeingBumpHeapAllocator
have been put behind interfaces;TrieAccessor
s are now injected theTrieStorage
dependency on construction;Endpoint
enumeration of all host api endpoints has been introduced, holding "just data", i.e. the signatures of the host api endpoints;HostApiImpl
class is introduced to explicitly hold implementations of the endpoints and to simplify creation ofImportObject
s exhaustively;Runtime
andRuntimeBuilder
have been renamed toWasmRuntimeInstace
andWasmRuntimeInstanceBuilder
(names are WIP) and now obtain an explicitContext
object on construction;Other notable changes (outside the
hybrid
package) which were necessary to achieve this decoupling:BlockState
field ofTrieStorage
, as it breaks separation of concerns;TrieStorage
is no longer a static singleton instance, as it is an implicit member of theContext
(through theTrieAccessor
);