input-output-hk / hermes

🏛️ Hermes is a high-availability blockchain voting database that acts as a distributed storage and event processor for voting events, proposals, and actions.
https://input-output-hk.github.io/hermes
Apache License 2.0
13 stars 2 forks source link

🛠️ [TASK] : wasmtime Resources management #257

Open Mr-Leshiy opened 1 month ago

Mr-Leshiy commented 1 month ago

Summary

Implement a generalised solution to safely manage wasmtime::component::Resource<> objects.

Description

Probable implementation of such ResourceManager could look like this:

trait ResourceObject<T> {
    fn allocate(params: T) -> Self;
    fn deallocation(&self);
}

struct ResourceManager<T, T1> {
  apps_state: DashMap<HermesAppName, DashMap<wasmtime::component::Resource<T1>,  T>>,

}

impl<T, T1> ResourceManager<T, T1> {
    pub(super) fn add_resource(&mut self, object: T) -> resource: wasmtime::component::Resource<T1>;

    pub(super) fn get_object(&self, resource: wasmtime::component::Resource<T1>) -> Option<T>;

    pub(super) fn delete_resource(&mut self, resource: wasmtime::component::Resource<T1>);

Updated already implemented solution for:

And any other runtime extensions which utilises wasmtime::component::Resource<> objects.