Instance on the Network

Hey guys, I would like your feedbacks on how to implement the Instance on the Network.

1. Instance hash calculation needs to change.

Instance hash is calculated with the instances’ env variables. But for security reason, the env variables are not save in any database. This cause the problem of not being able to recalculate the instance hash without the original envs. Only the engine that start the instance knows the env and thus the instance hash. This is not something good in order to implement the decentralized network correctly.

The solution is simply the calculate first the hash of the instance envs and to save it in the instance struct. Like this, anyone will be able to recalculate the instance hash without having to know the envs variable.

I already created an issue about this as it’s simple:

2. Properly define client and validator role

Both instance sdk create and delete function are doing 2 things:

  • Starting/stopping the docker services
  • Create/delete the instance object in the database
    To implement the decentralized network correctly, we need to separate better those 2 functions in 2 separate steps to define properly what the local engine have to do (client / instance sdk), and what the tendermint validator engine have to do (validator / instance backend).

I suggest the following logic:

Instance creation

  1. In InstanceSDK.Create:
    1. Calculate instance hash to check if instance doesn’t already run locally. If yes, return error.
    2. Download source and start instance in docker. Wait for it to start.
    3. Create transaction with message msgCreateInstance. This message contain the data of the instance (service hash and env hash) and also the address of the account that start this instance, we we call it node.
  2. In InstanceBackend.Create
    1. Create the instance struct. Calculate its hash.
    2. Check if instance exist in db. If not, create it. If already exist, continue.
    3. Register node as running this instance

Instance deletion

Basically the same as previous block but in reverse:

  1. unregister the node from the blockchain by executing a transaction.
  2. once tx confirmed, stop the local instance in docker

3. List of nodes that runs instances

Each node will have the responsibility to register and unregister itself from the instance, like this the whole network knows who is running what.
But what is the best way to store them?

We could simply add an array of nodes in the instance struct, but it will require to update the instance object over and over.
I’m suggesting to create a new store where each entry is referencing the instance hash and the node address (similar to ownership sdk). Like this it’s very simple to check if the node is register or can unregister itself.
The big question is “who” is managing this new store? It is directly instance sdk? Is it a new instance runner sdk? See Immutable data on Tendermint to answer.

The solution is simply the calculate first the hash of the instance envs and to save it in the instance struct. Like this, anyone will be able to recalculate the instance hash without having to know the envs variable.

Why someone want to recalculate those hashes? If you are able to get the isntance struct why you can’t use instance hash directly?

Instance creation

how/when instance sdk create will be called? SDK firsth then msgCreateInstance will call Backend right?