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

all: add support for new state expiration ledger entries #913

Merged
merged 24 commits into from
Sep 1, 2023

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Sep 1, 2023

What

Add support for the new state expiration ledger entries,

This PR also changes getLedgerEntries method so that doesn't filter out expired ledger entries. It simply returns whatever is in the database.

Why

Fixes #873

Known limitations

I left a few TODOs in the CLI, namely:

  1. We should test that some invariants hold in meta matches for the bump/restore commands.
  2. I haven't been able to update get_contract_spec_from_storage() with respect to expirations since I don't think the storage book-keeps expiration ledger entries.

@willemneal could you please take a look at the items above? Also, could you do some testing on the CLI once this is merged? Unfortunately, the XDR is out of sync with futurenet so you will have to use a local network.

We should probably start improving CLI testing considerably (particularly, integration tests against soroban-rpc). I wasn't comfortable fixing (2) since there were no tests covering it (AFICT).

Also, we should probably just get rid of the sandbox mode once and for all.

@2opremio 2opremio force-pushed the state-expiration-updates branch 2 times, most recently from d9e0051 to 22f0dd5 Compare September 1, 2023 10:45
@2opremio 2opremio force-pushed the state-expiration-updates branch from 22f0dd5 to 0e414da Compare September 1, 2023 10:46
@2opremio
Copy link
Contributor Author

2opremio commented Sep 1, 2023

To reviewers: Given the tight deadline for the testnet release, please let's not get picky with stuff which wouldn't be a problem in production.

It's fine to note it as a comment and create separate tickets, but let's not block the PR.

cmd/soroban-cli/src/commands/contract/bump.rs Outdated Show resolved Hide resolved
cmd/soroban-cli/src/commands/contract/read.rs Show resolved Hide resolved
cmd/soroban-cli/src/commands/contract/read.rs Outdated Show resolved Hide resolved
cmd/soroban-cli/src/utils.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@tsachiherman tsachiherman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you've already identified yourself, querying both the ledgerEntry and it's corresponding ledgerExpirationEntry would be better done on the go side; I think that a good starting point for that would be adding an optional expiration ledger sequence to the LedgerKeyAndEntry data structure.
Also - we could use some clarification from core whether the access to the expiration ledger entry is counted as an additional entry access or not. ( it might be a special case ).

@2opremio
Copy link
Contributor Author

2opremio commented Sep 1, 2023

Also - we could use some clarification from core whether the access to the expiration ledger entry is counted as an additional entry access or not. ( it might be a special case ).

I doubt it since the host doesn't track them and AFAIU otherwise integration tests wouldn't had worked. But this is a question for @sisuresh

@2opremio 2opremio force-pushed the state-expiration-updates branch from 2200d2f to 315b6b1 Compare September 1, 2023 13:29
Copy link
Contributor

@tsachiherman tsachiherman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that one thing that is missing is the deletion of EvictedTemporaryLedgerKeys.
These need to be deleted as soon as they become stale, since temporary entries could not be restored.

@2opremio
Copy link
Contributor Author

2opremio commented Sep 1, 2023

I believe that one thing that is missing is the deletion of EvictedTemporaryLedgerKeys. These need to be deleted as soon as they become stale, since temporary entries could not be restored.

Yes, that's why I had created #914

@tsachiherman
Copy link
Contributor

I think that it shouldn't be a testnet blocker here, but we should add some type of validation when inserting the ledger entries into the database to ensure that we always have "pairs" of entry + expiration.
The alternative to that is to add this during the simulation & getledgerenttries, but that won't fix the situation.

@2opremio
Copy link
Contributor Author

2opremio commented Sep 1, 2023

I think that it shouldn't be a testnet blocker here, but we should add some type of validation when inserting the ledger entries into the database to ensure that we always have "pairs" of entry + expiration.

This is Core's responsibility, I don't think we should be testing the metadata. Regardless, please create a separate ticket if you think this is important and let's get this merged.

@sisuresh
Copy link
Contributor

sisuresh commented Sep 1, 2023

Also - we could use some clarification from core whether the access to the expiration ledger entry is counted as an additional entry access or not. ( it might be a special case ).

I doubt it since the host doesn't track them and AFAIU otherwise integration tests wouldn't had worked. But this is a question for @sisuresh

Accessing the ExpirationEntry does not count as an additional entry access wrt the number of entries accessed, but we do charge for the bytes written in compute_rent_fee (which I believe you already use).

@2opremio 2opremio enabled auto-merge (squash) September 1, 2023 15:20
} => match executable {
ContractExecutable::Token => {
// TODO/FIXME: I don't think it will work for token contracts, since we don't store them in the state?
let res = soroban_spec::read::parse_raw(&token::StellarAssetSpec::spec_xdr());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec doesn't come from the state, just the entry that points to the token contract so this does work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know the spec is obtained separately. What I meant is that, AFAIU, we don't store ContractInstance entries for token contracts since the user provides no wasm.

Maybe I am wrong, though, if that's the case, can you point me where that happens?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A non Wasm contract instance still needs to store the fact that it's a token.

Copy link
Contributor Author

@2opremio 2opremio Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A non Wasm contract instance still needs to store the fact that it's a token.

Yes, but my point is that we only seem to update the state when a wasm file is provided, which doesn't for token contracts.

Thus, when invoking a token contract, the state won't have its ledger entries.

@tsachiherman
Copy link
Contributor

As you've already identified yourself, querying both the ledgerEntry and it's corresponding ledgerExpirationEntry would be better done on the go side; I think that a good starting point for that would be adding an optional expiration ledger sequence to the LedgerKeyAndEntry data structure. Also - we could use some clarification from core whether the access to the expiration ledger entry is counted as an additional entry access or not. ( it might be a special case ).

@2opremio I've created #916, which implements all the go-side code that would require to support retrieving the LedgerExpirationSeq while getting the ledger entries. I think that it would be best to fully merge your pr first before applying the other.

@2opremio
Copy link
Contributor Author

2opremio commented Sep 1, 2023

I am not sure this makes sense unless we also hide the expiration ledger entries from the end user. Otherwise the expiration field is redundant.

@tsachiherman
Copy link
Contributor

I don’t think this makes sense unless we also hide the expiration ledger entries from the end user. Otherwise the expiration field is redundant.

I wouldn't "hide" them explicitly, rather than allowing the user to explore remaining lifetime.
In particular, I'd like to save the js code of doing hash calculations and unnecessary parsing to get this value.

@2opremio
Copy link
Contributor Author

2opremio commented Sep 1, 2023

I understand the motivation but What’s the point of allowing to query expiration entries if you are providing the expiration as part of the result? I would go one way or the other, otherwise it’s confusing.

@2opremio 2opremio merged commit 135102e into main Sep 1, 2023
19 of 20 checks passed
@2opremio 2opremio deleted the state-expiration-updates branch September 1, 2023 22:34
@2opremio
Copy link
Contributor Author

2opremio commented Sep 1, 2023

Intentionally merged with a few CLI TODOs:

  1. we should test bump and restore commands, for which I added ledger entry pattern match which I am not 100% will work
  2. there is still some code pending clarification all: add support for new state expiration ledger entries #913 (comment) (waiting for your reply @willemneal :) )

.map(|c| c.encoded_key.len() as u32 + c.old_entry_size_bytes)
.map(
|c| {
let mut size = c.encoded_key.len() as u32 + c.old_entry_size_bytes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I missed this - We no longer need to count the key. @2opremio should I open a follow up PR?

Copy link
Contributor Author

@2opremio 2opremio Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was aware. I will fix it later on (it's not critical for the tesnet release since it will only add some overhead in the resource estimation)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, if you want to open a PR, by all means! I was assuming you have enough on your plate already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it then since it's not critical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

soroban-rpc: add support for expiration ledger entries
6 participants