Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Epic] M1: Support temporary and persistent storage #54

Open
3 of 5 tasks
konnov opened this issue May 15, 2024 · 3 comments
Open
3 of 5 tasks

[Epic] M1: Support temporary and persistent storage #54

konnov opened this issue May 15, 2024 · 3 comments
Assignees
Labels
epics Top-level issues

Comments

@konnov
Copy link
Contributor

konnov commented May 15, 2024

Soroban has unusual features regarding data persistence. We are not accounting for that currently.


Some high-level issues; for the full list, see the milestone

@andrey-kuprianov
Copy link
Collaborator

It looks like this is going to be a problem

            durability: xdr.ContractDataDurability.persistent(),

The problem is that durability represents independent keyspaces in ledgers, see here https://developers.stellar.org/docs/learn/smart-contract-internals/state-archival. In particular:

const EXAMPLE_KEY: Symbol = symbol_short!("KEY");
env.storage().persistent().set(&EXAMPLE_KEY, 1);
env.storage().temporary().set(&EXAMPLE_KEY, 2);

env.storage().persistent().get(&EXAMPLE_KEY); // Returns Ok(1)
env.storage().temporary().get(&EXAMPLE_KEY); // Returns Ok(2)

i.e. persistent , temporary , and instance are all independent keyspaces, and they all are used in various combinations in contracts. Thus retrieving only the keys which are persistent would be a heavy mistake on our side.

As our setter contract uses instance storage, but it seems to work when being retrieved as persistent, then most probably persistent and instance are the same from the retrieval perspective... But the storage API still distinguishes between them; probably that's for setting the TTL. Otoh temporary should surely fail to be retrieved as the above code snippet demonstrates.

Here are the examples of usages of all three qualifiers:

One way to test that would be to deploy both Timelock and Token contracts, and to try fetcher on both of them. But I did have problems with the Token contract, specifically with the allowance part... So another way would be to extend the Setter contract with some storage variables of all three kinds, and test on it.

@thpani thpani self-assigned this Jun 3, 2024
@thpani
Copy link
Collaborator

thpani commented Jun 4, 2024

I've extended the setter contract like this:

env.storage().instance().set(&MY_U32, &zero_u32);
env.storage().temporary().set(&MY_U32, &1_u32);
env.storage().persistent().set(&MY_U32, &2_u32);

It appears that persistent, instance and temporary indeed are three separate address spaces:

vscode ➜ /workspaces/solarkraft/ContractExamples (th/qol-tests) $ soroban contract invoke --source-account alice --id CB3YKTHSSIZPVKHBFWSSFHMYU3M4V27GE2CJK6NZVBIXMT2HRZ2HXBJR --network testnet -- get_u32
0
vscode ➜ /workspaces/solarkraft/ContractExamples (th/qol-tests) $ soroban contract read --durability temporary --source-account alice --id CB3YKTHSSIZPVKHBFWSSFHMYU3M4V27GE2CJK6NZVBIXMT2HRZ2HXBJR --network testnet --key MY_U32
MY_U32,1,1954002,1971281
vscode ➜ /workspaces/solarkraft/ContractExamples (th/qol-tests) $ soroban contract read --durability persistent --source-account 
alice --id CB3YKTHSSIZPVKHBFWSSFHMYU3M4V27GE2CJK6NZVBIXMT2HRZ2HXBJR --network testnet --key MY_U32
MY_U32,2,1954002,4027601

Although, for some reason soroban contract read does not support instance durability, so I had to soroban contract invoke instead.

@thpani thpani added the enhancement New feature or request label Jun 17, 2024
@thpani thpani changed the title Figure out how to handle TTL and temporary state Support temporary and persistent storage Jun 25, 2024
@thpani thpani changed the title Support temporary and persistent storage [Epic] M1: Support temporary and persistent storage Sep 2, 2024
@thpani thpani added the epics Top-level issues label Sep 2, 2024
@thpani
Copy link
Collaborator

thpani commented Sep 9, 2024

In addition to keying the storage by contract id (#121), we will need to key the storage by durability.

@thpani thpani removed the enhancement New feature or request label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epics Top-level issues
Projects
None yet
Development

No branches or pull requests

3 participants