-
Notifications
You must be signed in to change notification settings - Fork 676
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
feat: account serialization overhaul #12794
Conversation
ee8d576
to
2fb8991
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12794 +/- ##
==========================================
- Coverage 70.46% 70.45% -0.01%
==========================================
Files 847 847
Lines 175079 174994 -85
Branches 175079 174994 -85
==========================================
- Hits 123369 123296 -73
+ Misses 46451 46445 -6
+ Partials 5259 5253 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
2fb8991
to
76cd99b
Compare
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.
Nice work!
pub fn set_permanent_storage_bytes(&mut self, permanent_storage_bytes: StorageUsage) { | ||
self.permanent_storage_bytes = permanent_storage_bytes; | ||
match self { | ||
Self::V1(v1) => { |
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.
Not sure about this, because permanent storage bytes can only be set for V2 accounts and at the time of their creation. But anyway, plan to remove NEP-491 so feel free to leave it as it is.
core/primitives-core/src/account.rs
Outdated
permanent_storage_bytes, | ||
code_hash: self.code_hash(), | ||
storage_usage: self.storage_usage(), | ||
version: version, |
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.
mini nit: just version
core/primitives-core/src/account.rs
Outdated
}) | ||
let versioned_account = BorshVersionedAccount::deserialize_reader(rd)?; | ||
let account = match versioned_account { | ||
BorshVersionedAccount::V2(account_v1) => Account::V2(account_v1), |
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.
should not be V2(account_v2)
?
core/primitives-core/src/account.rs
Outdated
return Err(serde::de::Error::custom( | ||
"permanent storage bytes positive amount exists for account version older than V2", | ||
"permanent storage bytes exists for V1 account", |
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.
nit: the err message is a bit unclear
"permanent storage bytes exists for V1 account", | |
"permanent storage bytes should not be set for V1 account", |
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.
good point, thanks!
There is ongoing work on [global contracts](#12716) that addresses the problem near/NEPs#491 was originally designed to solve. NEP-491 code is quite messy and has been around for about a year. We no longer see external interest in this feature, but if the need arises in the future, we can always restore the code. Reverts most of (because some part is used by #12794): - #9600 - #10701 Also, #11005 can be closed.
Change
Account
to be enum and use different representations for serde and borsh ser/deser:SerdeAccount
is introduced for serde to maintain backward and forward compatibility. PreviouslyAccount
struct was directly annotated to support serde, we are opting out of this.BorshVersionedAccount
is introduced for borsh serialization. Accounts in old format are serialized directly asAccountV1
. Note that we continue serializing in old format when possible to avoid 16 bytes overhead of sentinel padding.Account::SERIALIZATION_SENTINEL
hack is preserved for borsh serialization as I could not find a better way to handle backward compatibility.This is part of #12716, in a separate PR global contracts related fields will be added as part of Account.