-
Notifications
You must be signed in to change notification settings - Fork 266
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
Storage rent 2022 #1798
Closed
Closed
Storage rent 2022 #1798
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request introduces 1 alert when merging 6ce0c2d into e135cc7 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 90bc896 into e135cc7 - view on LGTM.com new alerts:
|
fd17d69
to
ec02192
Compare
…) to blockTrack & transactionTrack
…sh, getStorageRentNodes, getRollbackNodes)
10f4c28
to
958a981
Compare
This pull request introduces 1 alert when merging 971d55f into c865587 - view on LGTM.com new alerts:
|
SonarCloud Quality Gate failed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RSKIP240 - Storage Rent
This PR implements the Storage Rent feature: RSKIP240.
Introduced changes
Trie
changes: added timestamp field.MutableTrie
operations: support to read and write the rent timestamp.Repository
methods: to retrieve tracked trie-nodes and to update rent.Class diagram including all the introduced changes and relevant stuff (green classes are new classes):
Repository
Now the repository has the capability of updating rent timestamps, as well another method has been added to retrieve a
RentedNode
from aTrackedNode
.Note that are other methods that shouldn't be part of the
Repository
but I've included them to prevent a major refactor:Those methods should be part of
MutableRepsotitory
(or a newMutableRepositoryTracked
)TransactionExecutor
Added a
StorageRentManager
to pay for storage rent a the end o the transaction execution (TransactionExecutor:525
). I've included it as the last step before doing the gas refund since rent payment should be the last consuming-gas operation of the processed transaction.Another important aspect is that rent payment is enabled only if the transaction:
Also, storage rent can be enabled or disabled from the config reference.
StorageRentManager
Added this class to perform the rent payment just for the payable nodes (the ones that are above the rent threshold). It first gets all the tracked trie keys from the
MutableRepository
then converts those keys toRentedNode
to perform the calculate the cumulative rent, then subtracts the gas consumed by the process (or OOG if it doesn't have enough gas), and finally invokes thetransactionTrack
to update rent timestamps.Note
RentedNodes
rents are fetched from theblockTrack
and not from thetransactionTrack
, that's because we want the storage rent data before executing the block. Also, rent is updated from thetransactionTrack
because it should be updated if the transaction succeeds.RepositoryLocator
Added a new method to return a
MutableRepository
with node-tracking capabilities.MutableRepository
I've wrapped all the read and write operations into "internal" methods (overrided in MutableRepositoryTracked). There are just 5 methods that perform read/write in the trie:
mutableTrie.get
mutableTrie.put
mutableTrie.getValueLength
mutableTrie.getValueHash
mutableTrie.deleteRecursive
mutableTrie.getStorageKeys
Now each time we want to use any of the above methods, we need to call it by using the internal method. This can be improved, but again, that's a major refactor and it goes out of scope.
MutableRepositoryTracked
This class extends MutableRepository to add tracking capabilities. This is useful for this project and the parallel transaction processing, in both scenarios we want to track all the read/written trie keys for the executed transaction, and since the
MutableRepository
is the main door, I've overridden internal methods to support tracking.Also, it's important to remark that now we're explicitly linking the repository hierarchy used for committing atomic state changes in the transaction execution. So each time we create a new child repository (
startTracking()
), we also provide the parent repository, and each time we commit/rollback changes, we also affect tracked nodes:commit()
: pass nodes to the parent repository.rollback()
: pass nodes as "rollback" to the parent repository.TrackedNode
Added this class to track trie nodes involved in transaction execution.
RentedNode
Added this class to calculate
MutableTrie
Added methods to update and get rent timestamps for a given trie-key.
Trie
If we add this RSKIP, then we'll have new trie nodes (with rent timestamp), so I've added support for these new trie-nodes by:
TrieSerializer
to serialize/deserialize trie elements.