Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reworks blockstore Column trait and LedgerColumn struct (#4416)
Column::serialize_index assumes that the &mut [u8] buffer is of size Column::KEY_LEN but there is no type-safety to ensure that: https://github.com/anza-xyz/agave/blob/c33c0392e/ledger/src/blockstore_db.rs#L779 Column::serialize_index also forces a non-idiomatic usage, e.g: https://github.com/anza-xyz/agave/blob/c33c0392e/ledger/src/blockstore_db.rs#L1624-L1627 https://github.com/anza-xyz/agave/blob/c33c0392e/ledger/src/blockstore_db.rs#L1636-L1639 Separately, Column::key allocates a vector on heap whereas an array suffices: https://github.com/anza-xyz/agave/blob/c33c0392e/ledger/src/blockstore_db.rs#L781 LedgerColumn takes a const K: usize type parameter which duplicates what Column::KEY_LEN is supposed to do: https://github.com/anza-xyz/agave/blob/c33c0392e/ledger/src/blockstore_db.rs#L1335 This also results in a very verbose LedgerColumn type specification which repeats Column::KEY_LEN in the type: https://github.com/anza-xyz/agave/blob/c33c0392e/ledger/src/blockstore.rs#L239-L260 LedgerColumn also duplicates Column::{key,serialize_index} by implementing key_from_index: https://github.com/anza-xyz/agave/blob/c33c0392e/ledger/src/blockstore_db.rs#L1427-L1432 This commit removes: const KEY_LEN: usize; fn serialize_index(key: &mut [u8], index: Self::Index); from the definition of Column trait and instead adds: type Key: AsRef<[u8]>; This also allows to remove const K: usize type parameter from the definition of LedgerColumn, remove LedgerColumn::key_from_index and avoid heap allocation in Collumn::key.
- Loading branch information