freenet-core
freenet-core copied to clipboard
Explore adding a lookup function in the contract API
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).
How does this differ from the related state mechanism (#167)?
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.
Two potential ways to generalize:
- The code to extract the desired data from the state could be supplied with the request as WASM
- 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).
Pivotal Tracker story: https://www.pivotaltracker.com/story/show/184058029