-
Notifications
You must be signed in to change notification settings - Fork 39
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
Bump live_until of contract data when putting to a dead key #1211
Conversation
d6e162f
to
70d8755
Compare
Yes, this assumption is correct. I'm not strictly opposed to this change and it seems pretty harmless (though there is a small chance it would hide some real issue), but I would prefer making sure the invariant is maintained correctly. Currently there are much more ways to do weird things via advancing ledgers; maybe we should simulate entry expiration while in tests... |
Minor correction: that's only true for the persistent entries; the temporary entries (such as allowance) would simply be treated as non-existent. |
Thanks for the review. I understand this may not be the correct solution.
This seems like a reasonable alternative. I would like some resolution to this issue as presently the behavior under test seems incorrect. Would exporting the snapshot from the Env and then reimporting it into a new Env cause the old entries to expire (vs. just mutating the sequence number on a single Env)? I don't understand exactly what snapshots are.
It doesn't appear to be the case that temporary entries are treated as non-existent - the bug I am seeing seems to be because the storage layer is confused about whether the entry exists or not - the |
To be clear, that's the invariant we have in core. Host indeed doesn't implement it, which is why I'm saying that we have a bigger general problem with using host in the test environment. When host is embedded by core, the invariants are:
Of course, neither of these invariants holds in the test environment at the moment. I think we should approach this holistically and probably try imitating the Core behavior via customizing Snapshot implementation. That would take some time though, so I've opened some issues: stellar/rs-soroban-sdk#1162, #1216
It depends on which snapshot you're talking about (there are storage snapshots and env snapshots). In any case, we probably want to emulate the proper expiration behavior. |
Since this isn't the right solution I'm closing it and following the linked issue. |
What
In
put_contract_data_into_ledger
, if the storage key already exists, set thelive_until
ledger to the maximum of either the existinglive_until
, or themin_live_until_ledger
.Why
Note I need careful review here because I may not understand what I am doing.
In the native token contract, writing an allowance involves calling
put_contract_data
thenextend_contract_data
.It is possible to put contract data to an existing storage key with a
live_until
value less than the current sequence number. In this case, the expiredlive_until
is maintained. If this happens, then in the subsequent call toextend_contract_data
,Storage::extend
will see the expiredlive_until
and return an error:The test case illustrates this.
Known limitations
It's possible this only happens in a test environment - maybe in a production environment these stale storage entries are not visible?
I see similar code in
store_contract_instance
but have not touched it.