freenet-core icon indicating copy to clipboard operation
freenet-core copied to clipboard

Explore adding a lookup function in the contract API

Open iduartgomez opened this issue 2 years ago • 4 comments

The change in the the API would be something similar to:

type Key = &[u8];

trait ContractInterface {
    fn lookup_data(
        key: Key
        state: State<'static>,
    ) -> Result<Vec<u8>, ContractError>;
}

We can make this work only locally (relatively straightforward) or also support it over the network (would add a bit more complexity to the node).

iduartgomez avatar Nov 25 '22 08:11 iduartgomez

How does this differ from the related state mechanism (#167)?

sanity avatar Nov 27 '22 00:11 sanity

The current interface does not provide any methods for accessing slices of the state based on some internal key, all instructions are based around the update control flow. This would be primarily useful for applications to have an effective way of getting a random piece of the state without having to send things through the websocket API and then having to be able to read and understand the contents of the state.

iduartgomez avatar Nov 27 '22 11:11 iduartgomez

Two potential ways to generalize:

  1. The code to extract the desired data from the state could be supplied with the request as WASM
  2. These requests can be sent over the network to other peers.
    • Intermediate peers can choose to request the entire state or just the desired part
    • If they would have cached the state anyway, then they request the entire state from downstream and just send the extracted part upstream
    • The purpose of this is to prevent denial-of-service (requests must always be cacheable).

sanity avatar Nov 27 '22 16:11 sanity

Pivotal Tracker story: https://www.pivotaltracker.com/story/show/184058029

github-actions[bot] avatar Dec 18 '22 01:12 github-actions[bot]