Skip to content
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

Increases account hash's stack buffer to hold 200 bytes of data #56

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion accounts-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ regex = { workspace = true }
seqlock = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_derive = { workspace = true }
smallvec = { workspace = true }
smallvec = { workspace = true, features = ["const_generics"] }
solana-bucket-map = { workspace = true }
solana-config-program = { workspace = true }
solana-frozen-abi = { workspace = true }
Expand Down
11 changes: 6 additions & 5 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6119,17 +6119,18 @@ impl AccountsDb {
}
let mut hasher = blake3::Hasher::new();

// allocate 128 bytes buffer on the stack
const BUFFER_SIZE: usize = 128;
const METADATA_SIZE: usize = 8 /* lamports */ + 8 /* rent_epoch */ + 1 /* executable */ + 32 /* owner */ + 32 /* pubkey */;
const REMAINING_SIZE: usize = BUFFER_SIZE - METADATA_SIZE;
// allocate a buffer on the stack that's big enough
// to hold a token account or a stake account
const META_SIZE: usize = 8 /* lamports */ + 8 /* rent_epoch */ + 1 /* executable */ + 32 /* owner */ + 32 /* pubkey */;
const DATA_SIZE: usize = 200; // stake acounts are 200 B and token accounts are 165-182ish B
const BUFFER_SIZE: usize = META_SIZE + DATA_SIZE;
let mut buffer = SmallVec::<[u8; BUFFER_SIZE]>::new();

// collect lamports, rent_epoch into buffer to hash
buffer.extend_from_slice(&lamports.to_le_bytes());
buffer.extend_from_slice(&rent_epoch.to_le_bytes());

if data.len() > REMAINING_SIZE {
if data.len() > DATA_SIZE {
// For larger accounts whose data can't fit into the buffer, update the hash now.
hasher.update(&buffer);
buffer.clear();
Expand Down
Loading