Skip to content

Comments

State expiration#3740

Closed
SirTyson wants to merge 25 commits intostellar:masterfrom
SirTyson:state-expiration-v2
Closed

State expiration#3740
SirTyson wants to merge 25 commits intostellar:masterfrom
SirTyson:state-expiration-v2

Conversation

@SirTyson
Copy link
Contributor

Description

Resolves #3697.

This provides initial support for state expiration. With this update, SQL and BucketListDB track entry entry lifetimes. Additionally, accessed entry lifetimes are automatically bumped, with an optional additional bump that can be defined in the footprint. While the BucketListDB behavior has been tested, I cannot run lifetime extension unit tests until this XDR change is merged and the state expiration interface updates have been merged on the Rust side. Until these changes and the unit tests pass, I'm leaving this as a draft, but there should be plenty to review in the mean time.

This PR does not enforce expiration, which means entries are accessible after they have expired and are not deleted. Additionally, while lifetime extensions are implemented, we do not yet charge any rent related fees.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

Copy link
Contributor

@dmkozh dmkozh left a comment

Choose a reason for hiding this comment

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

This is the first pass of review for stuff outside of bucketlist changes. There is nothing too problematic, but we do need to add fee-related and validation-related stuff (might actually be ok to do that in a separate PR - this really depends on the amount of changes).

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: that too short and not really readable, please use a more descriptive name, like footprintEntry. Also maybe a better interface would be a vec-to-vec converter (as you always deal with vecs for footprints).

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit hard to follow, would it be possible to break this down a bit (e.g. move lambdas out into functions and factor out some stuff in for (auto const& fe : resources.footprint.readOnly) loop).

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this works fine because you call this only on bumpable entries, but a safer check would be data.type() == CONTRACT_CODE || (type == CONTRACT_DATA && <your check>)

Copy link
Contributor

Choose a reason for hiding this comment

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

This part is actually kind of tricky. I think the right thing to do here is to charge the whole refundableFee as a part of resource fee and then do the refund for the unspent part. You'll also need to fail if you run out of fee.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this is correct - can't this cause exceeding the fee? Maybe it's safer to not do the bump at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to enforce the minimum expiration to prevent rent gaming since we can't actually start expiring UNIQUE and RESTORABLE entries until level 6 of the BucketList. This can cause exceeding the fee, but the thinking is that since rent payments are coming out of refundable fee, users should be able to be overly cautious and put in a little extra XLM for cases such as this. However we only need to enforce this on writes, not for the read-only entries. I think currently this applies the minimum to both read only and writes, so I'll change that, but keep the minimum as it is for modified entries.

src/util/types.h Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'm not sure this is the right place for LedgerEntry utils - somewhere in ledger folder would be more appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you can move this into if (success) below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do any pre-apply validation, like verify if bumps can be covered by the fees (maybe roughly?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to fail at validation step? It doesn't seem hard to avoid specifying too high expiration ledger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We shouldn't do this because the maxLedgerLifetime is a network config parameter that can change. For example, suppose a contract correctly bumps all entries it touches to the maximum rent at the time of 1 year. After the contract is deployed, the network config changes and the maximum lifetime is no 6 months. This previously valid contract is now invalid on every contract call if we fail at the validation step if lifetime bumps are too high

Copy link
Contributor

@dmkozh dmkozh left a comment

Choose a reason for hiding this comment

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

This is the first pass of review for stuff outside of bucketlist changes. There is nothing too problematic, but we do need to add fee-related and validation-related stuff (might actually be ok to do that in a separate PR - this really depends on the amount of changes).

@SirTyson SirTyson force-pushed the state-expiration-v2 branch from c50b274 to f20795a Compare May 26, 2023 17:29
@SirTyson SirTyson closed this May 29, 2023
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 rent_balance

8 participants