@@ -40,6 +40,7 @@ enum ImmutableOperation {
4040 Commit {
4141 has_metadata : bool ,
4242 metadata_size : usize ,
43+ advance_floor : bool ,
4344 } ,
4445 Prune {
4546 loc : u64 ,
@@ -179,24 +180,35 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
179180 ImmutableOperation :: Commit {
180181 has_metadata,
181182 metadata_size,
183+ advance_floor,
182184 } => {
183185 let metadata = if has_metadata {
184186 Some ( generate_value ( & mut rng, metadata_size) )
185187 } else {
186188 None
187189 } ;
188190
191+ let end = db. bounds ( ) . await . end ;
192+ let pending_count = pending_sets. len ( ) as u64 ;
189193 assign_pending_locations (
190194 & pending_sets,
191- db . bounds ( ) . await . end ,
195+ end,
192196 & mut keys_set,
193197 & mut set_locations,
194198 ) ;
195199 let mut batch = db. new_batch ( ) ;
196200 for ( k, v) in pending_sets. drain ( ..) {
197201 batch = batch. set ( k, v) ;
198202 }
199- let merkleized = batch. merkleize ( & db, metadata) ;
203+ let floor = if advance_floor {
204+ // Advance floor to the commit location (end of this batch).
205+ // total_size = end + pending_count + 1 (commit op).
206+ // Floor at the commit op is the maximum valid value.
207+ Location :: new ( * end + pending_count)
208+ } else {
209+ db. inactivity_floor_loc ( )
210+ } ;
211+ let merkleized = batch. merkleize ( & db, metadata, floor) ;
200212 db. apply_batch ( merkleized) . await . unwrap ( ) ;
201213 db. commit ( ) . await . unwrap ( ) ;
202214 last_commit_loc = Some ( db. bounds ( ) . await . end - 1 ) ;
@@ -216,7 +228,10 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
216228 for ( k, v) in pending_sets. drain ( ..) {
217229 batch = batch. set ( k, v) ;
218230 }
219- let merkleized = batch. merkleize ( & db, None ) ;
231+ // Set the floor to at least safe_loc so the prune succeeds,
232+ // but never below the current floor (monotonicity).
233+ let floor = safe_loc. max ( db. inactivity_floor_loc ( ) ) ;
234+ let merkleized = batch. merkleize ( & db, None , floor) ;
220235 db. apply_batch ( merkleized) . await . unwrap ( ) ;
221236 db. commit ( ) . await . unwrap ( ) ;
222237 last_commit_loc = Some ( db. bounds ( ) . await . end - 1 ) ;
@@ -247,7 +262,8 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
247262 for ( k, v) in pending_sets. drain ( ..) {
248263 batch = batch. set ( k, v) ;
249264 }
250- let merkleized = batch. merkleize ( & db, None ) ;
265+ let floor = db. inactivity_floor_loc ( ) ;
266+ let merkleized = batch. merkleize ( & db, None , floor) ;
251267 db. apply_batch ( merkleized) . await . unwrap ( ) ;
252268 db. commit ( ) . await . unwrap ( ) ;
253269 last_commit_loc = Some ( db. bounds ( ) . await . end - 1 ) ;
@@ -272,7 +288,8 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
272288 let safe_max_ops =
273289 NonZeroU64 :: new ( ( max_ops % MAX_PROOF_OPS ) . max ( 1 ) ) . unwrap ( ) ;
274290
275- let batch = db. new_batch ( ) . merkleize ( & db, None ) ;
291+ let floor = db. inactivity_floor_loc ( ) ;
292+ let batch = db. new_batch ( ) . merkleize ( & db, None , floor) ;
276293 db. apply_batch ( batch) . await . unwrap ( ) ;
277294 db. commit ( ) . await . unwrap ( ) ;
278295 last_commit_loc = Some ( db. bounds ( ) . await . end - 1 ) ;
@@ -307,7 +324,8 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
307324 for ( k, v) in pending_sets. drain ( ..) {
308325 batch = batch. set ( k, v) ;
309326 }
310- let merkleized = batch. merkleize ( & db, None ) ;
327+ let floor = db. inactivity_floor_loc ( ) ;
328+ let merkleized = batch. merkleize ( & db, None , floor) ;
311329 db. apply_batch ( merkleized) . await . unwrap ( ) ;
312330 db. commit ( ) . await . unwrap ( ) ;
313331 last_commit_loc = Some ( db. bounds ( ) . await . end - 1 ) ;
@@ -326,7 +344,8 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
326344 for ( k, v) in pending_sets. drain ( ..) {
327345 batch = batch. set ( k, v) ;
328346 }
329- let merkleized = batch. merkleize ( & db, None ) ;
347+ let floor = db. inactivity_floor_loc ( ) ;
348+ let merkleized = batch. merkleize ( & db, None , floor) ;
330349 db. apply_batch ( merkleized) . await . unwrap ( ) ;
331350 db. destroy ( ) . await . unwrap ( ) ;
332351 }
0 commit comments