This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
v1.1: Include account.owner into account hash #9918
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1259,25 +1259,34 @@ impl AccountsDB { | |
| } | ||
| } | ||
|
|
||
| pub fn hash_stored_account(slot: Slot, account: &StoredAccount) -> Hash { | ||
| pub fn hash_stored_account(slot: Slot, account: &StoredAccount, include_owner: bool) -> Hash { | ||
| Self::hash_account_data( | ||
| slot, | ||
| account.account_meta.lamports, | ||
| &account.account_meta.owner, | ||
| account.account_meta.executable, | ||
| account.account_meta.rent_epoch, | ||
| account.data, | ||
| &account.meta.pubkey, | ||
| include_owner, | ||
| ) | ||
| } | ||
|
|
||
| pub fn hash_account(slot: Slot, account: &Account, pubkey: &Pubkey) -> Hash { | ||
| pub fn hash_account( | ||
| slot: Slot, | ||
| account: &Account, | ||
| pubkey: &Pubkey, | ||
| include_owner: bool, | ||
| ) -> Hash { | ||
| Self::hash_account_data( | ||
| slot, | ||
| account.lamports, | ||
| &account.owner, | ||
| account.executable, | ||
| account.rent_epoch, | ||
| &account.data, | ||
| pubkey, | ||
| include_owner, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -1296,13 +1305,20 @@ impl AccountsDB { | |
| hasher.result() | ||
| } | ||
|
|
||
| pub fn include_owner_in_hash(slot: Slot) -> bool { | ||
| // Account hashing updated to include owner activates at this slot on the testnet | ||
| slot >= 14_000_000 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, my bad. This will not quite work for devnet............ devnet is still at around slot Gating logic is hard. Sorry about that. The excuse is that I only cared tds and mainnet-beta; that's already complicated enough to do flawless rolling update; not at all for devnet at the time of this pr.... This causes bankhash incompatibility between v1.1 branch and master branch for devnet: #10163 (comment) FYI: @CriesofCarrots |
||
| } | ||
|
|
||
| pub fn hash_account_data( | ||
| slot: Slot, | ||
| lamports: u64, | ||
| owner: &Pubkey, | ||
| executable: bool, | ||
| rent_epoch: Epoch, | ||
| data: &[u8], | ||
| pubkey: &Pubkey, | ||
| include_owner: bool, | ||
| ) -> Hash { | ||
| if lamports == 0 { | ||
| return Hash::default(); | ||
|
|
@@ -1328,6 +1344,10 @@ impl AccountsDB { | |
| hasher.hash(&[0u8; 1]); | ||
| } | ||
|
|
||
| if include_owner { | ||
| hasher.hash(&owner.as_ref()); | ||
| } | ||
|
|
||
| hasher.hash(&pubkey.as_ref()); | ||
|
|
||
| hasher.result() | ||
|
|
@@ -1522,7 +1542,11 @@ impl AccountsDB { | |
| let account = store.accounts.get_account(account_info.offset)?.0; | ||
|
|
||
| if check_hash { | ||
| let hash = Self::hash_stored_account(*slot, &account); | ||
| let hash = Self::hash_stored_account( | ||
| *slot, | ||
| &account, | ||
| Self::include_owner_in_hash(*slot), | ||
| ); | ||
| if hash != *account.hash { | ||
| mismatch_found.store(true, Ordering::Relaxed); | ||
| } | ||
|
|
@@ -1743,7 +1767,7 @@ impl AccountsDB { | |
| .iter() | ||
| .map(|(pubkey, account)| { | ||
| stats.update(account); | ||
| Self::hash_account(slot, account, pubkey) | ||
| Self::hash_account(slot, account, pubkey, Self::include_owner_in_hash(slot)) | ||
| }) | ||
| .collect(); | ||
|
|
||
|
|
@@ -3319,19 +3343,33 @@ pub mod tests { | |
| hash: &hash, | ||
| }; | ||
| let account = stored_account.clone_account(); | ||
| let expected_account_hash = | ||
| let expected_account_hash_without_owner = | ||
| Hash::from_str("GGTsxvxwnMsNfN6yYbBVQaRgvbVLfxeWnGXNyB8iXDyE").unwrap(); | ||
|
|
||
| assert_eq!( | ||
| AccountsDB::hash_stored_account(slot, &stored_account), | ||
| expected_account_hash, | ||
| AccountsDB::hash_stored_account(slot, &stored_account, false), | ||
| expected_account_hash_without_owner, | ||
| "StoredAccount's data layout might be changed; update hashing if needed." | ||
| ); | ||
| assert_eq!( | ||
| AccountsDB::hash_account(slot, &account, &stored_account.meta.pubkey), | ||
| expected_account_hash, | ||
| AccountsDB::hash_account(slot, &account, &stored_account.meta.pubkey, false), | ||
| expected_account_hash_without_owner, | ||
| "Account-based hashing must be consistent with StoredAccount-based one." | ||
| ); | ||
|
|
||
| let expected_account_hash_with_owner = | ||
| Hash::from_str("5iRNZVcAnq9JLYjSF2ibFhGEeq48r9Eq9HXxwm3BxywN").unwrap(); | ||
|
|
||
| assert_eq!( | ||
| AccountsDB::hash_stored_account(slot, &stored_account, true), | ||
| expected_account_hash_with_owner, | ||
| "StoredAccount's data layout might be changed; update hashing if needed (with owner)." | ||
| ); | ||
| assert_eq!( | ||
| AccountsDB::hash_account(slot, &account, &stored_account.meta.pubkey, true), | ||
| expected_account_hash_with_owner, | ||
| "Account-based hashing must be consistent with StoredAccount-based one (with owner)." | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
@@ -3472,7 +3510,7 @@ pub mod tests { | |
| let loaded_account = db.load_slow(&ancestors, key).unwrap().0; | ||
| assert_eq!( | ||
| loaded_account.hash, | ||
| AccountsDB::hash_account(some_slot, &account, &key) | ||
| AccountsDB::hash_account(some_slot, &account, &key, false) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.