refactor(block execution)!: showcase a MWE with explicit `Context` object
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.MemoryandFreeingBumpHeapAllocatorhave been put behind interfaces;TrieAccessors are now injected theTrieStoragedependency on construction;- regarding the host api:
- an
Endpointenumeration of all host api endpoints has been introduced, holding "just data", i.e. the signatures of the host api endpoints; - a
HostApiImplclass is introduced to explicitly hold implementations of the endpoints and to simplify creation ofImportObjects exhaustively;
- an
RuntimeandRuntimeBuilderhave been renamed toWasmRuntimeInstaceandWasmRuntimeInstanceBuilder(names are WIP) and now obtain an explicitContextobject on construction;
Other notable changes (outside the hybrid package) which were necessary to achieve this decoupling:
- remove the
BlockStatefield ofTrieStorage, as it breaks separation of concerns; TrieStorageis no longer a static singleton instance, as it is an implicit member of theContext(through theTrieAccessor);- [SIDE FIX / QUESTIONABLE] The runtime builder is now used for the runtimeVersionV1 endpoint instead of manual instantiation. More details at this commit: 21547d7005434d58ac867b4bca050219a99987fc.
Closing this as already implemented in #456.
