func (s *store) evictOuter(last *postage.Batch) error {
	// if capacity is positive nothing to evict
	if s.rs.Available >= 0 {
		return nil
	}
	err := s.store.Iterate(valueKeyPrefix, func(key, _ []byte) (bool, error) {
		batchID := valueKeyToID(key)
		b := last
		if !bytes.Equal(b.ID, batchID) {
			var err error
			b, err = s.Get(batchID)
			if err != nil {
				return true, fmt.Errorf("release get %x %v: %w", batchID, b, err)
			}
		}
		//  FIXME: this is needed only because  the statestore iterator does not allow seek, only prefix
		//  so we need to page through all the batches until outer limit is reached
		if b.Value.Cmp(s.rs.Outer) < 0 {
			return false, nil
		}
		// stop iteration  only if we consumed all batches of the same value as the one that put capacity above zero
		if s.rs.Available >= 0 && s.rs.Outer.Cmp(b.Value) != 0 {
			return true, nil
		}
		// unreserve outer PO of the lowest priority batch  until capacity is back to positive
		s.rs.Available += exp2(b.Depth - s.rs.Radius - 1)
		s.rs.Outer.Set(b.Value)
		return false, s.unreserve(b, s.rs.Radius)
	})
	if err != nil {
		return err
	}
	// add 1 to outer limit value so we dont hit on the same batch next time we iterate
	s.rs.Outer.Add(s.rs.Outer, big1)
	// if we consumed all batches, ie. we unreserved all chunks on the outer = depth PO
	//  then its time to  increase depth
	if s.rs.Available < 0 {
		s.rs.Radius++
		s.rs.Outer.Set(s.rs.Inner) // reset outer limit to inner limit
		return s.evictOuter(last)
	}
	return s.store.Put(reserveStateKey, s.rs)
}
// evictOuter is responsible for keeping capacity positive by unreserving lowest priority batches
evictOuter is responsible for keeping capacity positive by unreserving lowest priority batches
// evictOuter is responsible for keeping capacity positive by unreserving lowest priority batches
func (s *store) evictOuter(last *postage.Batch) error {
	if s.rs.Available >= 0 {
		return nil
	}
	err := s.store.Iterate(valueKeyPrefix, func(key, _ []byte) (bool, error) {
		batchID := valueKeyToID(key)
		b := last
		if !bytes.Equal(b.ID, batchID) {
			var err error
			b, err = s.Get(batchID)
			if err != nil {
				return true, fmt.Errorf("release get %x %v: %w", batchID, b, err)
			}
		}
		if b.Value.Cmp(s.rs.Outer) < 0 {
			return false, nil
		}
		if s.rs.Available >= 0 && s.rs.Outer.Cmp(b.Value) != 0 {
			return true, nil
		}
		s.rs.Available += exp2(b.Depth - s.rs.Radius - 1)
		s.rs.Outer.Set(b.Value)
		return false, s.unreserve(b, s.rs.Radius)
	})
	if err != nil {
		return err
	}
	s.rs.Outer.Add(s.rs.Outer, big1)
	if s.rs.Available < 0 {
		s.rs.Radius++
		s.rs.Outer.Set(s.rs.Inner) 
		return s.evictOuter(last)
	}
	return s.store.Put(reserveStateKey, s.rs)
}
func ( s * store ) evictOuter ( last * postage . Batch ) error { if s . rs . Available >= 0 { return nil } err := s . store . Iterate ( valueKeyPrefix , func ( key , _ [ ] byte ) ( bool , error ) { batchID := valueKeyToID ( key ) b := last if ! bytes . Equal ( b . ID , batchID ) { var err error b , err = s . Get ( batchID ) if err != nil { return true , fmt . Errorf ( " " , batchID , b , err ) } } if b . Value . Cmp ( s . rs . Outer ) < 0 { return false , nil } if s . rs . Available >= 0 && s . rs . Outer . Cmp ( b . Value ) != 0 { return true , nil } s . rs . Available += exp2 ( b . Depth - s . rs . Radius - 1 ) s . rs . Outer . Set ( b . Value ) return false , s . unreserve ( b , s . rs . Radius ) } ) if err != nil { return err } s . rs . Outer . Add ( s . rs . Outer , big1 ) if s . rs . Available < 0 { s . rs . Radius ++ s . rs . Outer . Set ( s . rs . Inner ) return s . evictOuter ( last ) } return s . store . Put ( reserveStateKey , s . rs ) }
evictOuter is responsible for keeping capacity positive by unreserving lowest priority batches
evictOuter is responsible for keeping capacity positive by unreserving lowest priority batches
// if capacity is positive nothing to evict //  FIXME: this is needed only because  the statestore iterator does not allow seek, only prefix //  so we need to page through all the batches until outer limit is reached // stop iteration  only if we consumed all batches of the same value as the one that put capacity above zero // unreserve outer PO of the lowest priority batch  until capacity is back to positive // add 1 to outer limit value so we dont hit on the same batch next time we iterate // if we consumed all batches, ie. we unreserved all chunks on the outer = depth PO //  then its time to  increase depth // reset outer limit to inner limit