-
Notifications
You must be signed in to change notification settings - Fork 674
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
Don't charge extra for trie deletions outside of contract execution #11507
Conversation
Theoretically this is a protocol change, and should have a separate protocol version, but I'm not sure if it's really needed. We are able to restart all nodes of statelessnet at once, right? Upgrading all of them at the same time should be enough to get things going. |
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.
Enabling/disabling a mode is an anti-pattern to me, because it requires mutability and more care from the struct owner - no one is protected from accidentally calling it in some other place and breaking costs. ChunkCache
also should not have been implemented this way :(
@Ekleog-NEAR inside a contract, is there a way to access keys other than ContractData
?
If not, I would just check a trie key type. Intuitively, the cost of removing all other key types is by several orders of magnitude higher, so they shouldn't be an issue.
Theoretically this is a protocol change, and should have a separate protocol version, but I'm not sure if it's really needed. We are able to restart all nodes of statelessnet at once, right? Upgrading all of them at the same time should be enough to get things going.
Yeah, I would prefer not adding new protocol version, it means more ugly code which we don't really need.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #11507 +/- ##
==========================================
+ Coverage 71.31% 71.32% +0.01%
==========================================
Files 787 787
Lines 159389 159391 +2
Branches 159389 159391 +2
==========================================
+ Hits 113667 113685 +18
+ Misses 40782 40773 -9
+ Partials 4940 4933 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Yeah this is a good point. It was easier for me to think about as an on/off switch that is turned to on during contract execution, but it's true that it's pretty error prone. Changed it to record only when removing |
During the execution of the contract RocksDB does get accessed with But I cannot claim that the contract is unable to construct an arbitrary list of tasks for the transaction runtime that would result in deletions that we don't want to see. For the reference you can check the |
LGTM. One sanity check though: is ContractData the only other key type we are interested in? are transfers also executed through contract data? how about account data deletions such as code, are they all considered in the category of Contract Data? |
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.
Added one question about ContractData. otherwise LGTM.
We are interested in |
I ran a manual test. First on Then I ran the same test on this branch: It looks like the change helps with handling congestion, or at least it doesn't hurt ;) |
I was actually thinking that we are entirely removing the recording, but in fact is it just the removing of the 2M-extra in the calculation, so restricting to ContractData is fine. |
To limit the amount of storage proof generated during chunk application we calculate the upper bound estimation of how big the storage proof will be, and stop executing receipts when this estimated size gets to big. When estimating we assume that every trie removals generates 2000 bytes of storage proof, because this is the maximum size that a malicious attacker could generate (#11069, #10890).
This estimation was meant to limit the size of proof generated while executing receipts, but currently it also applies to other trie removals performed by the runtime, for example when removing receipts from the delayed receipt queue. This is really wasteful - removing 1000 receipts would cause the estimation to jump by 2MB, hitting the soft limit. We don't really need to charge this much for internal operations performed by the runtime, they aren't malicious. Let's change is so that only contracts are charged extra for removals. This will avoid the extra big estimation caused by normal queue manipulation.
Refs: https://near.zulipchat.com/#narrow/stream/308695-nearone.2Fprivate/topic/Large.20number.20of.20delayed.20receipts.20in.20statelessnet/near/442878068