From 1e133bc067555df9fa2d60835f256d962d3aed98 Mon Sep 17 00:00:00 2001 From: Brooks Date: Tue, 5 Mar 2024 12:02:47 -0500 Subject: [PATCH] Increases account hash's stack buffer to hold 200 bytes of data (#56) --- accounts-db/Cargo.toml | 2 +- accounts-db/src/accounts_db.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/accounts-db/Cargo.toml b/accounts-db/Cargo.toml index 702f14f9f..0fc5a381f 100644 --- a/accounts-db/Cargo.toml +++ b/accounts-db/Cargo.toml @@ -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 } diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 1f3c36876..cf4d17745 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -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();