Skip to content

Commit

Permalink
feat: account serialization overhaul (#12794)
Browse files Browse the repository at this point in the history
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. Previously `Account` 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 as `AccountV1`. 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.
  • Loading branch information
pugachAG authored Jan 27, 2025
1 parent 6618737 commit 5b17d59
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 348 deletions.
4 changes: 2 additions & 2 deletions chain/chain/src/tests/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn build_chain() {
// cargo insta test --accept -p near-chain --features nightly -- tests::simple_chain::build_chain
let hash = chain.head().unwrap().last_block_hash;
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"GARF4HBtQJ41quFA9fvjHpbVYT4o15syhL3FkH1o7poT");
insta::assert_snapshot!(hash, @"24ZC3eGVvtFdTEok4wPGBzx3x61tWqQpves7nFvow2zf");
} else {
insta::assert_snapshot!(hash, @"3e2u5p2hUijQd7o5Dg1pK9QAHGZ9uCK19KDV86TJW78f");
}
Expand All @@ -51,7 +51,7 @@ fn build_chain() {

let hash = chain.head().unwrap().last_block_hash;
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"HiXuBfW5Xd6e8ZTbMhwtPEXeZxe7macc8DvaWryNdvcf");
insta::assert_snapshot!(hash, @"9enFQNcVUW65x3oW2iVdYSBxK9qFNETAixEQZLzXWeaQ");
} else {
insta::assert_snapshot!(hash, @"Gh5KqeboPbLh2ZwTqQLY2n5FQdPasFAEkPVfnM66LGjn");
}
Expand Down
Loading

0 comments on commit 5b17d59

Please sign in to comment.