@@ -92,8 +92,7 @@ pub(crate) unsafe fn read_entry_count_from_bytes_unchecked(data: &[u8]) -> usize
9292///
9393/// The function checks:
9494/// 1. The buffer is large enough to contain the entry count.
95- /// 2. The declared entry count is ≤ `MAX_ENTRIES`.
96- /// 3. The buffer length is sufficient to hold the declared number of entries.
95+ /// 2. The buffer length is sufficient to hold the declared number of entries.
9796///
9897/// It returns `Ok(())` if the data is well-formed, otherwise an appropriate
9998/// `ProgramError` describing the issue.
@@ -123,34 +122,34 @@ impl SlotHashEntry {
123122}
124123
125124impl < T : Deref < Target = [ u8 ] > > SlotHashes < T > {
126- /// Creates a `SlotHashes` instance from mainnet-sized data with full validation .
125+ /// Creates a `SlotHashes` instance with validation of the entry count and buffer size .
127126 ///
128- /// This constructor expects exactly MAX_SIZE (20,488) bytes and performs validation
129- /// of the entry count. Callers with different buffer sizes must pad their data
130- /// to the required length or use test-specific constructors .
127+ /// This constructor validates that the buffer has at least enough bytes to contain
128+ /// the declared number of entries. The buffer can be any size >= the minimum required,
129+ /// making it suitable for both full MAX_SIZE buffers and smaller test data .
131130 /// Does not validate that entries are sorted in descending order.
132131 #[ inline( always) ]
133132 pub fn new ( data : T ) -> Result < Self , ProgramError > {
134133 parse_and_validate_data ( & data) ?;
135- // SAFETY: `parse_and_validate_data` verifies that the data slice is exactly
136- // `MAX_SIZE ` bytes long and that the declared entry count is within
137- // `MAX_ENTRIES` , thus upholding all invariants required by
138- // `SlotHashes::new_unchecked`.
134+ // SAFETY: `parse_and_validate_data` verifies that the data slice has at least
135+ // `NUM_ENTRIES_SIZE ` bytes for the entry count and enough additional bytes to
136+ // contain the declared number of entries , thus upholding all invariants required
137+ // by `SlotHashes::new_unchecked`.
139138 Ok ( unsafe { Self :: new_unchecked ( data) } )
140139 }
141140
142- /// Creates a `SlotHashes` instance assuming golden mainnet buffer size .
143- /// Reads the entry count from the data but assumes the buffer is MAX_SIZE bytes.
144- /// Callers with different needs must pad their incomplete sysvar data up to
145- /// the required length in test or new network contexts .
141+ /// Creates a `SlotHashes` instance without validation .
142+ ///
143+ /// This is an unsafe constructor that bypasses all validation checks for performance.
144+ /// In debug builds, it still runs `parse_and_validate_data` as a sanity check .
146145 ///
147146 /// # Safety
148147 ///
149148 /// This function is unsafe because it does not validate the data size or format.
150149 /// The caller must ensure:
151150 /// 1. The underlying byte slice in `data` represents valid SlotHashes data
152151 /// (length prefix + entries, where entries are sorted in descending order by slot).
153- /// 2. The data slice contains exactly MAX_SIZE (20,488) bytes.
152+ /// 2. The data slice has at least `NUM_ENTRIES_SIZE + (declared_entries * ENTRY_SIZE)` bytes.
154153 /// 3. The first 8 bytes contain a valid entry count in little-endian format.
155154 ///
156155 #[ inline( always) ]
0 commit comments