-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[Gas Metering] Add storage_rebate
to Object
and introduce gas price
#1254
Conversation
storage_rebate
to Object
and introduce gas pricestorage_rebate
to Object
and introduce gas price
storage_rebate
to Object
and introduce gas pricestorage_rebate
to Object
and introduce gas price
gas_status: &mut SuiGasStatus, | ||
gas_object_size: usize, | ||
gas_object: &mut Object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could take Object
to avoid the clone at 133 i the caller happens to have ownership?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot unfortunately. We still need to actually deduct gas from the gas_object after this function returns.
object.object_data_size(), | ||
storage_rebate, | ||
)?; | ||
if !object.is_read_only() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to instead do
if object.is_read_only() { continue }
at the beginning of the loop, or even at the beginning of the function? At least based on the name, it sounds like charge_gas_for_storage_changes
should never be called for immutable objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not. Newly published package will show up in self.written
as well, and we need to charge for storage too.
Codecov Report
@@ Coverage Diff @@
## main #1254 +/- ##
==========================================
+ Coverage 81.72% 81.84% +0.11%
==========================================
Files 99 99
Lines 20613 20683 +70
==========================================
+ Hits 16847 16929 +82
+ Misses 3766 3754 -12
Continue to review full report at Codecov.
|
This PR does two things together, since they are tightly coupled.
What we are trying to do here is to properly implement Alonso's storage rebate design:
Whenever an object is being mutated, what we do is to first think that this original object is being deleted, and hence we are giving back a storage rebate, and then the new version of the object is being inserted, which will charge a new storage cost.
Because we want to make sure that the storage fund never gets depleted, the storage rebate on the same object can never be bigger (in SUI) than the storage cost when the object was added. To achieve this, we need to track the amount of SUI the previous mutation paid for the storage, and this amount will be used as the rebate next time this same object is being mutated.
This PR achieves this by adding these two things:
storage_rebate
field toObject
. This value represents the amount of rebate (in SUI) someone will get if they ever delete this object from storage. It's set by the previous transaction that mutated this object. In this implementation, what we do is that every time when an object is being mutated (not just deleted), we first "delete" the old object and provide the storage rebate, and then charge the storage cost based on the current storage gas unit price.